changeset 69f659bdf3b3 in modules/purchase:default
details: https://hg.tryton.org/modules/purchase?cmd=changeset;node=69f659bdf3b3
description:
        Add contact and invoice party

        issue8992
        review274701003
diffstat:

 CHANGELOG              |   2 +
 doc/index.rst          |   2 +
 party.py               |   1 +
 purchase.py            |  53 ++++++++++++++++++++++++++++++++++++++-----------
 view/purchase_form.xml |   9 ++++++-
 5 files changed, 53 insertions(+), 14 deletions(-)

diffs (178 lines):

diff -r 6c79ab8c771e -r 69f659bdf3b3 CHANGELOG
--- a/CHANGELOG Thu Mar 19 19:08:10 2020 +0100
+++ b/CHANGELOG Sat Mar 28 14:25:57 2020 +0100
@@ -1,3 +1,5 @@
+* Add contact and invoice party on purchase
+
 Version 5.4.0 - 2019-11-04
 * Bug fixes (see mercurial logs for details)
 * Add customer code for supplier on party
diff -r 6c79ab8c771e -r 69f659bdf3b3 doc/index.rst
--- a/doc/index.rst     Thu Mar 19 19:08:10 2020 +0100
+++ b/doc/index.rst     Sat Mar 28 14:25:57 2020 +0100
@@ -13,6 +13,8 @@
 of them are optional or completed with sensible default values:
 
 - Party: The supplier.
+- Contact: The contact who received the order.
+- Invoice Party: An optional different party that sends the invoice.
 - Invoice Address: The invoice address of the supplier.
 - Supplier Reference: Allow to keep track of the supplier reference
   for this order.
diff -r 6c79ab8c771e -r 69f659bdf3b3 party.py
--- a/party.py  Thu Mar 19 19:08:10 2020 +0100
+++ b/party.py  Sat Mar 28 14:25:57 2020 +0100
@@ -41,6 +41,7 @@
         return super(PartyReplace, cls).fields_to_replace() + [
             ('purchase.product_supplier', 'party'),
             ('purchase.purchase', 'party'),
+            ('purchase.purchase', 'invoice_party'),
             ]
 
 
diff -r 6c79ab8c771e -r 69f659bdf3b3 purchase.py
--- a/purchase.py       Thu Mar 19 19:08:10 2020 +0100
+++ b/purchase.py       Sat Mar 28 14:25:57 2020 +0100
@@ -107,13 +107,28 @@
         select=True, depends=['state'])
     party_lang = fields.Function(fields.Char('Party Language'),
         'on_change_with_party_lang')
+    contact = fields.Many2One(
+        'party.contact_mechanism', "Contact",
+        search_context={
+            'related_party': Eval('party'),
+            },
+        depends=['party'])
+    invoice_party = fields.Many2One('party.party', "Invoice Party",
+        states={
+            'readonly': ((Eval('state') != 'draft')
+                | Eval('lines', [0])),
+            },
+        depends=['state'])
     invoice_address = fields.Many2One('party.address', 'Invoice Address',
-        domain=[('party', '=', Eval('party'))],
+        domain=[
+            ('party', '=', If(Bool(Eval('invoice_party')),
+                    Eval('invoice_party'), Eval('party'))),
+            ],
         states={
             'readonly': Eval('state') != 'draft',
             'required': ~Eval('state').in_(['draft', 'quotation', 'cancel']),
             },
-        depends=['state', 'party'])
+        depends=['party', 'invoice_party', 'state'])
     warehouse = fields.Many2One('stock.location', 'Warehouse',
         domain=[('type', '=', 'warehouse')], states=_states,
         depends=_depends)
@@ -368,26 +383,30 @@
     def default_shipment_state():
         return 'none'
 
-    @fields.depends('party', 'payment_term', 'lines')
+    @fields.depends('party', 'invoice_party', 'payment_term', 'lines')
     def on_change_party(self):
         pool = Pool()
         Currency = pool.get('currency.currency')
         cursor = Transaction().connection.cursor()
         table = self.__table__()
-        self.invoice_address = None
+        if not self.invoice_party:
+            self.invoice_address = None
         self.payment_term = self.default_payment_term()
         if not self.lines:
             self.currency = self.default_currency()
             self.currency_digits = self.default_currency_digits()
-        self.invoice_address = None
         if self.party:
-            self.invoice_address = self.party.address_get(type='invoice')
+            if not self.invoice_party:
+                self.invoice_address = self.party.address_get(type='invoice')
             if self.party.supplier_payment_term:
                 self.payment_term = self.party.supplier_payment_term
 
             if not self.lines:
+                invoice_party = (
+                    self.invoice_party.id if self.invoice_party else None)
                 subquery = table.select(table.currency,
-                    where=table.party == self.party.id,
+                    where=(table.party == self.party.id)
+                    & (table.invoice_party == invoice_party),
                     order_by=table.id,
                     limit=10)
                 cursor.execute(*subquery.select(subquery.currency,
@@ -399,6 +418,14 @@
                     self.currency = Currency(currency_id)
                     self.currency_digits = self.currency.digits
 
+    @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('currency')
     def on_change_with_currency_digits(self, name=None):
         if self.currency:
@@ -702,15 +729,16 @@
             journal, = journals
         else:
             journal = None
+        party = self.invoice_party or self.party
 
         return Invoice(
             company=self.company,
             type='in',
             journal=journal,
-            party=self.party,
+            party=party,
             invoice_address=self.invoice_address,
             currency=self.currency,
-            account=self.party.account_payable_used,
+            account=party.account_payable_used,
             payment_term=self.payment_term,
             )
 
@@ -1169,7 +1197,8 @@
                 self.purchase.company.id if self.purchase.company else -1),
             }
 
-    @fields.depends('product', 'unit', 'purchase', '_parent_purchase.party',
+    @fields.depends('product', 'unit', 'purchase',
+        '_parent_purchase.party', '_parent_purchase.invoice_party',
         'product_supplier', methods=['compute_taxes', 'compute_unit_price',
             '_get_product_supplier_pattern'])
     def on_change_product(self):
@@ -1177,8 +1206,8 @@
             return
 
         party = None
-        if self.purchase and self.purchase.party:
-            party = self.purchase.party
+        if self.purchase:
+            party = self.purchase.invoice_party or self.purchase.party
 
         # Set taxes before unit_price to have taxes in context of purchase
         # price
diff -r 6c79ab8c771e -r 69f659bdf3b3 view/purchase_form.xml
--- a/view/purchase_form.xml    Thu Mar 19 19:08:10 2020 +0100
+++ b/view/purchase_form.xml    Sat Mar 28 14:25:57 2020 +0100
@@ -4,10 +4,15 @@
 <form col="6">
     <label name="party"/>
     <field name="party"/>
+    <label name="contact"/>
+    <field name="contact"/>
+    <label name="number"/>
+    <field name="number"/>
+    <label name="invoice_party"/>
+    <field name="invoice_party"/>
     <label name="invoice_address"/>
     <field name="invoice_address"/>
-    <label name="number"/>
-    <field name="number"/>
+    <newline/>
     <label name="description"/>
     <field name="description" colspan="3"/>
     <label name="reference"/>

Reply via email to