changeset 1007f94bae58 in modules/sale_subscription:default
details: 
https://hg.tryton.org/modules/sale_subscription?cmd=changeset;node=1007f94bae58
description:
        Add contact and invoice party

        issue8992
        review274701003
diffstat:

 CHANGELOG                  |   1 +
 doc/index.rst              |   2 ++
 subscription.py            |  37 ++++++++++++++++++++++++++++++-------
 view/subscription_form.xml |  12 ++++++++++--
 4 files changed, 43 insertions(+), 9 deletions(-)

diffs (125 lines):

diff -r 4554ac59f567 -r 1007f94bae58 CHANGELOG
--- a/CHANGELOG Thu Mar 26 09:25:37 2020 +0100
+++ b/CHANGELOG Sat Mar 28 14:25:57 2020 +0100
@@ -1,3 +1,4 @@
+* Add contact and invoice party on subscription
 * Allow invoices to be created in advance
 
 Version 5.4.0 - 2019-11-04
diff -r 4554ac59f567 -r 1007f94bae58 doc/index.rst
--- a/doc/index.rst     Thu Mar 26 09:25:37 2020 +0100
+++ b/doc/index.rst     Sat Mar 28 14:25:57 2020 +0100
@@ -12,6 +12,8 @@
 extensive list of the fields:
 
 - Party: The customer.
+- Contact: The contact who placed the order.
+- Invoice Party: An optional different party to invoice.
 - Invoice Address: The invoice address of the customer.
 - Number: The internal reference of the subscription.
 - Reference: The optional external reference of the subscription.
diff -r 4554ac59f567 -r 1007f94bae58 subscription.py
--- a/subscription.py   Thu Mar 26 09:25:37 2020 +0100
+++ b/subscription.py   Sat Mar 28 14:25:57 2020 +0100
@@ -60,16 +60,28 @@
             },
         depends=['state'],
         help="The party who subscribes.")
+    contact = fields.Many2One(
+        'party.contact_mechanism', "Contact",
+        search_context={
+            'related_party': Eval('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')),
+            ('party', '=', If(Bool(Eval('invoice_party',)),
+                    Eval('invoice_party'), Eval('party'))),
             ],
         states={
             'readonly': Eval('state') != 'draft',
             'required': ~Eval('state').in_(['draft']),
             },
-        depends=['party', 'state'])
+        depends=['party', 'invoice_party', 'state'])
     payment_term = fields.Many2One(
         'account.invoice.payment_term', "Payment Term",
         states={
@@ -196,12 +208,22 @@
     def default_state(cls):
         return 'draft'
 
-    @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_party:
+                self.invoice_address = self.party.address_get(type='invoice')
+            self.payment_term = self.party.customer_payment_term
+
+    @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')
-            self.payment_term = self.party.customer_payment_term
 
     @classmethod
     def set_number(cls, subscriptions):
@@ -362,13 +384,14 @@
     def _get_invoice(self):
         pool = Pool()
         Invoice = pool.get('account.invoice')
+        party = self.invoice_party or self.party
         invoice = Invoice(
             company=self.company,
             type='out',
-            party=self.party,
+            party=party,
             invoice_address=self.invoice_address,
             currency=self.currency,
-            account=self.party.account_receivable_used,
+            account=party.account_receivable_used,
             )
         invoice.on_change_type()
         invoice.payment_term = self.payment_term
diff -r 4554ac59f567 -r 1007f94bae58 view/subscription_form.xml
--- a/view/subscription_form.xml        Thu Mar 26 09:25:37 2020 +0100
+++ b/view/subscription_form.xml        Sat Mar 28 14:25:57 2020 +0100
@@ -4,14 +4,22 @@
 <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"/>
     <field name="reference"/>
+
     <notebook colspan="6">
         <page string="Subscription" id="subscription">
             <label name="start_date"/>

Reply via email to