-
-
Notifications
You must be signed in to change notification settings - Fork 320
[14.0][IMP] l10n_it_fatturapa_in: intermediary contact creation depending by vat #4621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 14.0
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errata approvazione
ed30f19
to
c28b517
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functional ok
37f7831
to
f6b31d2
Compare
1e7be0b
to
4c3b6da
Compare
2f2ce53
to
9b1bc90
Compare
3a52536
to
67261be
Compare
67261be
to
7c229f6
Compare
7c229f6
to
3095bbc
Compare
0fe8bf8
to
06f1a50
Compare
e917c43
to
2f752bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mi pare che questi 3 commit siano un po' mischiati, se possibile sarebbe meglio fare:
- 1 commit
[REF]
di refactoring prima dove estrai tutti i metodi che ti serve estrarre, senza cambiare il comportamento che c'era prima della PR.
Se possibile, come scrivevo in #4621 (comment), sulla linea di #3100 visto che prima o poi dovremo allinearci - 1 commit
[IMP]
dove aggiungi la nuova funzionalità
# XXX maybe San Marino needs special formatting too? | ||
else: | ||
vat = id_codice | ||
vat = self.extract_vat(DatiAnagrafici) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Questo commit ha lo scopo di
[IMP] l10n_it_fatturapa_in: intermediary contact creation depending b…
…y vat
(riesci a riassumere in modo che non vada a capo?)
Però ci sono dentro diversi refactoring, sicuramente utili, che non fanno capire cosa sia davvero necessario allo scopo del commit e cosa no.
Puoi riunire i refactoring in un commit dedicato, precedente agli altri?
Nota che il refactoring per definizione non dovrebbe cambiare il comportamento attuale.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ora è tutto in un commit 👍
"name": line.name, | ||
"name": line.lastname, | ||
"firstname": line.firstname or False, | ||
"lastname": line.lastname or line.name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Questa modifica non mi pare abbia a che fare con lo scopo del commit
[IMP] l10n_it_fatturapa_in: better partner search
Forse andrebbe nel commit in cui è stato definito il wizard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ora è tutto in un commit 👍
) | ||
|
||
def getPartnerBase(self, DatiAnagrafici): # noqa: C901 | ||
def getPartnerBase(self, DatiAnagrafici, partnerCreate=True): # noqa: C901 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ora che il metodo è stato semplificato forse si può riattivare il linting
def getPartnerBase(self, DatiAnagrafici, partnerCreate=True): # noqa: C901 | |
def getPartnerBase(self, DatiAnagrafici, partnerCreate=True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
return vals | ||
|
||
def _find_partners_by_cf_vat(self, DatiAnagrafici): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In che senso questa ricerca è meglio di com'era prima?
A me sembra che venga cercato esattamente allo stesso modo, sono solo stati estratti dei metodi, oppure mi son perso qualche pezzo?
Se è solo un'estrazione di metodi puoi metterla in un commit di refactoring [REF]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ora è tutto in un commit 👍
"name": name, | ||
"vat": vat, | ||
"name": partner_vals.get("name"), | ||
"firstname": partner_vals.get("firstname"), | ||
"lastname": partner_vals.get("lastname"), | ||
"vat": partner_vals["vat"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ci sono diversi valori in partner_vals
che sono stati faticosamente trovati da _prepare_partner_values
, e altri override potrebbero includerne altri.
Sicuramente aggiungerei il codice fiscale perché insieme alla partita IVA identifica il partner (come hai visto nelle diverse search
).
Dopo questa PR l'intermediario avrà meno campi valorizzati, che è una regressione, puoi correggere?
Per riuscire a passarli tutti al wizard si potrebbero mettere in una stringa con json.dump
e salvarli in un campo del wizard che poi riotterrà il dizionario con json.loads
, cosa ne pensi?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Questo non è risolto
{ | ||
"name": line.lastname, | ||
"firstname": line.firstname or False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Questo come ha a che fare con
[IMP] l10n_it_fatturapa_in: commercial partner search improvement
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ora è tutto in un commit 👍
|
||
return vals | ||
|
||
def _find_commercial_partner(self, DatiAnagrafici, partners): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In che senso questa ricerca è meglio di com'era prima?
A me sembra che venga cercato esattamente allo stesso modo, sono solo stati estratti dei metodi, oppure mi son perso qualche pezzo?
Se è solo un'estrazione di metodi puoi metterla in un commit di refactoring [REF]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non avevamo detto si semplificare il metodo get_partner_base
? per questo ho pensato fosse una buona idea cercare i partner associati in base al dominio in una funzione e poi il commercial partner in un'altra
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ora è tutto in un commit 👍
vat = self.extract_vat(DatiAnagrafici) | ||
vat = False | ||
if DatiAnagrafici.IdFiscaleIVA: | ||
id_paese = DatiAnagrafici.IdFiscaleIVA.IdPaese.upper() | ||
id_codice = re.sub(r"\W+", "", DatiAnagrafici.IdFiscaleIVA.IdCodice).upper() | ||
# Format Italian VAT ID to always have 11 char | ||
# to avoid validation error when creating the given partner | ||
if id_paese == "IT" and not id_codice.startswith("IT"): | ||
vat = "IT{}".format(id_codice.rjust(11, "0")[:11]) | ||
# XXX maybe San Marino needs special formatting too? | ||
else: | ||
vat = id_codice |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perché ora non va più bene extract_vat
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A me sembra meglio la nuova funzione. Anche perché così riusciamo ad evitare una funzione che deve restituire il cf (estrarre ripetutamente il cf dai dati anagrafici in giro non è una ripetizione del codice?). Prima extract_vat
andava a restituire solo la partita iva quindi sostituire quella funzione con una che dia anche il cf mi sembra più pratico da usare quando serve. Poi la funzione l'ho spostata con le altre nuove prima era in fondo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
estrarre ripetutamente il cf dai dati anagrafici in giro non è una ripetizione del codice?
Secondo me no perché si parla semplicemente di recuperare il valore di un campo:
cf = DatiAnagrafici.CodiceFiscale
è come quando devi recuperare il partner di una fattura: partner = invoice.partner_id
è scritto mille volte, ma non è codice ripetuto.
Ora che c'è la nuova _define_vat_fiscalcode
va bene, quando scrissi il commento era stato rimosso extract_vat
e c'era semplicemente scritto tutto l'if
:
👍
Quando ho finito di fare le modifiche la mia intenzione sarà quella di fare squash dei commit perché ovviamente le modifiche fatte fino ad ora erano dati da tentativi di implementazione. Nella descrizione del commit ho messo che è stato fatto anche un refactoring iniziale. Fare un commit REF risulterebbe ora troppo complesso perché significherebbe ripristinare tutto quello che ho fatto e ripeterlo da capo ed è secondo me un lavoro evitabile |
aa8db53
to
1ad5242
Compare
data = json.loads(line.intermediary_data_json) | ||
if isinstance(data, str): | ||
data = json.loads(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perché serve ripetere loads
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errore mio
partner = self.getPartnerBase( | ||
Intermediary.DatiAnagrafici, partnerCreate=False | ||
) | ||
|
||
if isinstance(partner, int): | ||
partner_id = self.env["res.partner"].browse(partner) | ||
invoice.write({"intermediary": partner_id}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qui mi pare ci sia un po' di confusione tra l'ID del partner (un intero) e un record del partner perché non si sa bene cosa potrà uscire dalla nuova implementazione di getPartnerBase
.
In generale penso sia più chiaro usare il suffisso _id
quando si parla di un ID (es partner_id
), e nessun suffisso quando si parla di un record (es partner
).
Quindi suggerirei
partner = self.getPartnerBase( | |
Intermediary.DatiAnagrafici, partnerCreate=False | |
) | |
if isinstance(partner, int): | |
partner_id = self.env["res.partner"].browse(partner) | |
invoice.write({"intermediary": partner_id}) | |
partner_id = self.getPartnerBase( | |
Intermediary.DatiAnagrafici, partnerCreate=False | |
) | |
if isinstance(partner_id, int): | |
invoice.write({"intermediary": partner_id}) |
che è anche più simile al codice prima di questa PR (era intermediary_id
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Però in questo caso getPartnerBase
può restituire o in intero (se trova il partner) oppure un dizionario che verra sfruttato nella funzione di import. Per questo avevo pensato di generalizzare e scrivere partner. Infatti c'è anche la seconda condizione sotto che valuta se viene restituito un dizionario
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Però in questo caso
getPartnerBase
può restituire o in intero (se trova il partner) oppure un dizionario che verra sfruttato nella funzione di import. Per questo avevo pensato di generalizzare e scrivere partner. Infatti c'è anche la seconda condizione sotto che valuta se viene restituito un dizionario
Ok, però dentro partner
di solito c'è un record; se non è così si crea confusione nel resto del codice.
Ad esempio
partner_id = self.env["res.partner"].browse(partner)
è il contrario di quello che si farebbe normalmente.
Se non si sa di che tipo sia la variabile puoi chiamarla tipo partner_id_or_vals
.
Ho come la sensazione che questo metodo che può restituire un dizionario o un intero ci stia complicando la vita, forse sarebbe più semplice qualcosa del tipo:
partner_id = self._find_partner(...)
if partner_id:
invoice.write(...)
else:
partner_values = self._prepare_partner_values(...)
Cosa ne pensi?
elif isinstance(partner, bool): | ||
invoice.write({"intermediary": False}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qui non si entra mai perché il primo if
controlla se partner
è un intero e
>>> isinstance(False, int)
True
if Intermediary.DatiAnagrafici.IdFiscaleIVA: | ||
partner = self.getPartnerBase( | ||
Intermediary.DatiAnagrafici, partnerCreate=False | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perché ora questo viene fatto solo quando c'è il nodo Intermediary.DatiAnagrafici.IdFiscaleIVA
?
Può essere utile per recuperare i dati dai nodi del XML anche se non troverà la partita IVA, come veniva fatto prima di questa PR.
Era già stato segnalato in #4621 (comment).
|
||
return vals | ||
|
||
def _find_commercial_partner(self, DatiAnagrafici, partners): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quando c'è solo un record in partners
questo metodo ritorna False
, dovrebbe invece restituire il commercial partner dell'unico record in partners
.
|
||
return vals | ||
|
||
def _find_commercial_partner(self, DatiAnagrafici, partners): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In questo metodo cf
e vat
vengono usati solo per loggare l'inconsistenza, si può evitare di calcolarli sempre?
"vat": vat if vat else False, | ||
"fiscalcode": cf if cf else False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Se vat
(o cf
) sono vuoti, cosa cambia scriverci invece False
?
Se non cambia nulla puoi rimettere com'era prima?
"vat": vat if vat else False, | |
"fiscalcode": cf if cf else False, | |
"vat": vat, | |
"fiscalcode": cf, |
"name": denominazione, | ||
"firstname": nome, | ||
"lastname": cognome, | ||
"vat": vat, | ||
"invoice_id": invoice.id, | ||
"intermediary_data_json": { | ||
"name": denominazione, | ||
"firstname": nome, | ||
"lastname": cognome, | ||
"vat": vat, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"name": denominazione, | |
"firstname": nome, | |
"lastname": cognome, | |
"vat": vat, | |
"invoice_id": invoice.id, | |
"intermediary_data_json": { | |
"name": denominazione, | |
"firstname": nome, | |
"lastname": cognome, | |
"vat": vat, | |
}, | |
"invoice_id": invoice.id, | |
"intermediary_data_json": { | |
"name": denominazione, | |
"firstname": nome, | |
"lastname": cognome, | |
"vat": vat, | |
}, |
I valori dei primi campi potrebbero essere calcolati in base a quello che c'è in intermediary_data_json
invece di ripeterli.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
È necessario allora implementare una funzione in WizardCheckIntermediaryVatLine
che estragga i dati da intermediary_data_json
"lastname": new_data.get("lastname") | ||
or new_data.get("name"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Come mai non mettiamo invece un name
dedicato? C'era nelle vecchie versioni della PR. Sarebbe da valorizzare solo quando c'è Denominazione
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ci può stare
21ffd97
to
1da39c1
Compare
1da39c1
to
f319210
Compare
No description provided.