changeset df8bccdb549e in modules/purchase_amendment:default details: https://hg.tryton.org/modules/purchase_amendment?cmd=changeset&node=df8bccdb549e description: Add invoice party on amendment
issue11667 review447321003 diffstat: purchase.py | 29 ++++++++++++++++++++++++++--- view/purchase_amendment_line_form.xml | 3 +++ 2 files changed, 29 insertions(+), 3 deletions(-) diffs (85 lines): diff -r f4908bb7f8ac -r df8bccdb549e purchase.py --- a/purchase.py Thu Jun 02 11:23:09 2022 +0200 +++ b/purchase.py Sun Oct 09 13:12:51 2022 +0200 @@ -202,10 +202,20 @@ 'invisible': Eval('action') != 'party', 'required': Eval('action') == 'party', }) + invoice_party = fields.Many2One( + 'party.party', "Invoice Party", + states={ + 'readonly': Eval('state') != 'draft', + 'invisible': Eval('action') != 'party', + }, + search_context={ + 'related_party': Eval('party'), + }) invoice_address = fields.Many2One( 'party.address', "Invoice Address", domain=[ - ('party', '=', Eval('party')), + ('party', '=', If(Eval('invoice_party'), + Eval('invoice_party'), Eval('party'))), ], states={ 'readonly': Eval('state') != 'draft', @@ -301,6 +311,7 @@ '_parent_amendment.purchase', '_parent_amendment._parent_purchase.payment_term', '_parent_amendment._parent_purchase.party', + '_parent_amendment._parent_purchase.invoice_party', '_parent_amendment._parent_purchase.invoice_address', '_parent_amendment._parent_purchase.warehouse') def on_change_amendment(self): @@ -308,6 +319,7 @@ self.payment_term = self.amendment.purchase.payment_term self.party = self.amendment.purchase.party + self.invoice_party = self.amendment.purchase.invoice_party self.invoice_address = self.amendment.purchase.invoice_address self.warehouse = self.amendment.purchase.warehouse @@ -355,10 +367,20 @@ self.product = self.product_supplier = self.description = None self.quantity = self.unit = self.unit_price = None - @fields.depends('party') + @fields.depends('party', 'invoice_party') def on_change_party(self): - self.invoice_address = None + if not self.invoice_party: + self.invoice_address = None if self.party: + if not self.invoice_address: + self.invoice_address = self.party.address_get(type='invoice') + + @fields.depends('party', 'invoice_party') + def on_change_invoice_party(self): + if self.invoice_party: + self.invoice_address = self.invoice_party.address_get( + type='invoice') + elif self.party: self.invoice_address = self.party.address_get(type='invoice') @fields.depends('line') @@ -389,6 +411,7 @@ def _apply_party(self, purchase, purchase_line): purchase.party = self.party + purchase.invoice_party = self.invoice_party purchase.invoice_address = self.invoice_address def _apply_warehouse(self, purchase, purchase_line): diff -r f4908bb7f8ac -r df8bccdb549e view/purchase_amendment_line_form.xml --- a/view/purchase_amendment_line_form.xml Thu Jun 02 11:23:09 2022 +0200 +++ b/view/purchase_amendment_line_form.xml Sun Oct 09 13:12:51 2022 +0200 @@ -14,6 +14,9 @@ <newline/> <label name="party"/> <field name="party"/> + <newline/> + <label name="invoice_party"/> + <field name="invoice_party"/> <label name="invoice_address"/> <field name="invoice_address"/> <newline/>