changeset 0d680014600a in modules/purchase:default
details: https://hg.tryton.org/modules/purchase?cmd=changeset&node=0d680014600a
description:
        Add monetary field

        issue10598
        review338511002
diffstat:

 product.py                                    |   5 +-
 purchase.py                                   |  61 ++++++++------------------
 view/product_supplier_price_form.xml          |   2 +-
 view/product_supplier_price_list_sequence.xml |   2 +-
 view/product_supplier_price_tree.xml          |   2 +-
 view/purchase_form.xml                        |   6 +-
 view/purchase_line_form.xml                   |   4 +-
 view/purchase_line_tree.xml                   |   4 +-
 view/purchase_line_tree_sequence.xml          |   4 +-
 view/purchase_tree.xml                        |   2 +-
 10 files changed, 36 insertions(+), 56 deletions(-)

diffs (244 lines):

diff -r 31bb67e988c7 -r 0d680014600a product.py
--- a/product.py        Thu Jul 29 09:06:38 2021 +0200
+++ b/product.py        Sat Aug 21 09:09:56 2021 +0200
@@ -14,6 +14,7 @@
 from trytond.transaction import Transaction
 from trytond.tools import lstrip_wildcard
 
+from trytond.modules.currency.fields import Monetary
 from trytond.modules.product import price_digits
 
 from .exceptions import PurchaseUOMWarning
@@ -454,8 +455,8 @@
         required=True,
         domain=[('quantity', '>=', 0)],
         help='Minimal quantity.')
-    unit_price = fields.Numeric('Unit Price', required=True,
-        digits=price_digits)
+    unit_price = Monetary(
+        "Unit Price", currency='currency', required=True, digits=price_digits)
 
     uom = fields.Function(fields.Many2One('product.uom', 'UOM',
         help="The unit in which the quantity is specified."),
diff -r 31bb67e988c7 -r 0d680014600a purchase.py
--- a/purchase.py       Thu Jul 29 09:06:38 2021 +0200
+++ b/purchase.py       Sat Aug 21 09:09:56 2021 +0200
@@ -27,6 +27,7 @@
 from trytond.modules.account_product.exceptions import AccountError
 from trytond.modules.company.model import (
     employee_field, set_employee, reset_employee)
+from trytond.modules.currency.fields import Monetary
 from trytond.modules.product import price_digits, round_price
 
 from .exceptions import PurchaseQuotationError, PartyLocationError
@@ -152,29 +153,24 @@
                 | (Eval('lines', [0]) & Eval('currency'))),
             },
         depends=['state'])
-    currency_digits = fields.Function(fields.Integer('Currency Digits'),
-        'on_change_with_currency_digits')
     lines = fields.One2Many('purchase.line', 'purchase', 'Lines',
         states=_states, depends=_depends)
     comment = fields.Text('Comment')
-    untaxed_amount = fields.Function(fields.Numeric('Untaxed',
-            digits=(16, Eval('currency_digits', 2)),
-            depends=['currency_digits']), 'get_amount')
-    untaxed_amount_cache = fields.Numeric('Untaxed Cache',
-        digits=(16, Eval('currency_digits', 2)),
-        depends=['currency_digits'])
-    tax_amount = fields.Function(fields.Numeric('Tax',
-            digits=(16, Eval('currency_digits', 2)),
-            depends=['currency_digits']), 'get_amount')
-    tax_amount_cache = fields.Numeric('Tax Cache',
-        digits=(16, Eval('currency_digits', 2)),
-        depends=['currency_digits'])
-    total_amount = fields.Function(fields.Numeric('Total',
-            digits=(16, Eval('currency_digits', 2)),
-            depends=['currency_digits']), 'get_amount')
-    total_amount_cache = fields.Numeric('Total Cache',
-        digits=(16, Eval('currency_digits', 2)),
-        depends=['currency_digits'])
+    untaxed_amount = fields.Function(Monetary(
+            "Untaxed", currency='currency', digits='currency'),
+        'get_amount')
+    untaxed_amount_cache = Monetary(
+        "Untaxed Cache", currency='currency', digits='currency')
+    tax_amount = fields.Function(Monetary(
+            "Tax", currency='currency', digits='currency'),
+        'get_amount')
+    tax_amount_cache = Monetary(
+        "Tax Cache", currency='currency', digits='currency')
+    total_amount = fields.Function(Monetary(
+            "Total", currency='currency', digits='currency'),
+        'get_amount')
+    total_amount_cache = Monetary(
+        "Total Cache", currency='currency', digits='currency')
     invoice_method = fields.Selection([
             ('manual', 'Manual'),
             ('order', 'Based On Order'),
@@ -397,15 +393,6 @@
             company = Company(company)
             return company.currency.id
 
-    @staticmethod
-    def default_currency_digits():
-        Company = Pool().get('company.company')
-        company = Transaction().context.get('company')
-        if company:
-            company = Company(company)
-            return company.currency.digits
-        return 2
-
     @classmethod
     def default_invoice_method(cls, **pattern):
         Configuration = Pool().get('purchase.configuration')
@@ -430,7 +417,6 @@
         self.invoice_method = self.default_invoice_method()
         if not self.lines:
             self.currency = self.default_currency()
-            self.currency_digits = self.default_currency_digits()
         if self.party:
             if not self.invoice_party:
                 self.invoice_address = self.party.address_get(type='invoice')
@@ -459,7 +445,6 @@
                 row = cursor.fetchone()
                 if row:
                     self.currency, self.payment_term, self.invoice_method = row
-                    self.currency_digits = self.currency.digits
 
             if self.party.supplier_payment_term:
                 self.payment_term = self.party.supplier_payment_term
@@ -472,12 +457,6 @@
         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:
-            return self.currency.digits
-        return 2
-
     @fields.depends('party')
     def on_change_with_party_lang(self, name=None):
         Config = Pool().get('ir.configuration')
@@ -1115,15 +1094,15 @@
     product_uom_category = fields.Function(
         fields.Many2One('product.uom.category', 'Product Uom Category'),
         'on_change_with_product_uom_category')
-    unit_price = fields.Numeric('Unit Price', digits=price_digits,
+    unit_price = Monetary(
+        "Unit Price", currency='currency', digits=price_digits,
         states={
             'invisible': Eval('type') != 'line',
             'required': Eval('type') == 'line',
             'readonly': Eval('purchase_state') != 'draft',
             }, depends=['type', 'purchase_state'])
-    amount = fields.Function(fields.Numeric('Amount',
-            digits=(16,
-                Eval('_parent_purchase', {}).get('currency_digits', 2)),
+    amount = fields.Function(Monetary(
+            "Amount", currency='currency', digits='currency',
             states={
                 'invisible': ~Eval('type').in_(['line', 'subtotal']),
                 },
diff -r 31bb67e988c7 -r 0d680014600a view/product_supplier_price_form.xml
--- a/view/product_supplier_price_form.xml      Thu Jul 29 09:06:38 2021 +0200
+++ b/view/product_supplier_price_form.xml      Sat Aug 21 09:09:56 2021 +0200
@@ -10,5 +10,5 @@
     <field name="quantity" symbol="uom"/>
     <newline/>
     <label name="unit_price"/>
-    <field name="unit_price" symbol="currency"/>
+    <field name="unit_price"/>
 </form>
diff -r 31bb67e988c7 -r 0d680014600a 
view/product_supplier_price_list_sequence.xml
--- a/view/product_supplier_price_list_sequence.xml     Thu Jul 29 09:06:38 
2021 +0200
+++ b/view/product_supplier_price_list_sequence.xml     Sat Aug 21 09:09:56 
2021 +0200
@@ -4,5 +4,5 @@
 <tree sequence="sequence">
     <field name="product_supplier" expand="1"/>
     <field name="quantity" symbol="uom"/>
-    <field name="unit_price" symbol="currency" expand="1"/>
+    <field name="unit_price" expand="1"/>
 </tree>
diff -r 31bb67e988c7 -r 0d680014600a view/product_supplier_price_tree.xml
--- a/view/product_supplier_price_tree.xml      Thu Jul 29 09:06:38 2021 +0200
+++ b/view/product_supplier_price_tree.xml      Sat Aug 21 09:09:56 2021 +0200
@@ -4,5 +4,5 @@
 <tree>
     <field name="product_supplier" expand="1"/>
     <field name="quantity" symbol="uom"/>
-    <field name="unit_price" symbol="currency"/>
+    <field name="unit_price"/>
 </tree>
diff -r 31bb67e988c7 -r 0d680014600a view/purchase_form.xml
--- a/view/purchase_form.xml    Thu Jul 29 09:06:38 2021 +0200
+++ b/view/purchase_form.xml    Sat Aug 21 09:09:56 2021 +0200
@@ -39,11 +39,11 @@
             </group>
             <group col="2" colspan="2" id="amount" yfill="1">
                 <label name="untaxed_amount" xalign="1.0" xexpand="1"/>
-                <field name="untaxed_amount" symbol="currency" xalign="1.0" 
xexpand="0"/>
+                <field name="untaxed_amount" xalign="1.0" xexpand="0"/>
                 <label name="tax_amount" xalign="1.0" xexpand="1"/>
-                <field name="tax_amount" symbol="currency" xalign="1.0" 
xexpand="0"/>
+                <field name="tax_amount" xalign="1.0" xexpand="0"/>
                 <label name="total_amount" xalign="1.0" xexpand="1"/>
-                <field name="total_amount" symbol="currency" xalign="1.0" 
xexpand="0"/>
+                <field name="total_amount" xalign="1.0" xexpand="0"/>
             </group>
         </page>
         <page string="Other Info" id="info">
diff -r 31bb67e988c7 -r 0d680014600a view/purchase_line_form.xml
--- a/view/purchase_line_form.xml       Thu Jul 29 09:06:38 2021 +0200
+++ b/view/purchase_line_form.xml       Sat Aug 21 09:09:56 2021 +0200
@@ -20,9 +20,9 @@
             <label name="unit"/>
             <field name="unit"/>
             <label name="unit_price"/>
-            <field name="unit_price" symbol="currency"/>
+            <field name="unit_price"/>
             <label name="amount"/>
-            <field name="amount" symbol="currency"/>
+            <field name="amount"/>
             <label id="delivery_date" string="Delivery Date:"/>
             <group id="delivery_date" col="-1">
                 <field name="delivery_date" xexpand="0"/>
diff -r 31bb67e988c7 -r 0d680014600a view/purchase_line_tree.xml
--- a/view/purchase_line_tree.xml       Thu Jul 29 09:06:38 2021 +0200
+++ b/view/purchase_line_tree.xml       Sat Aug 21 09:09:56 2021 +0200
@@ -8,7 +8,7 @@
     <field name="product_supplier" expand="1"/>
     <field name="summary" expand="1"/>
     <field name="quantity" symbol="unit"/>
-    <field name="unit_price" symbol="currency"/>
+    <field name="unit_price"/>
     <field name="taxes"/>
-    <field name="amount" symbol="currency"/>
+    <field name="amount"/>
 </tree>
diff -r 31bb67e988c7 -r 0d680014600a view/purchase_line_tree_sequence.xml
--- a/view/purchase_line_tree_sequence.xml      Thu Jul 29 09:06:38 2021 +0200
+++ b/view/purchase_line_tree_sequence.xml      Sat Aug 21 09:09:56 2021 +0200
@@ -8,7 +8,7 @@
     <field name="product_supplier" expand="1"/>
     <field name="summary" expand="1"/>
     <field name="quantity" symbol="unit"/>
-    <field name="unit_price" symbol="currency"/>
+    <field name="unit_price"/>
     <field name="taxes"/>
-    <field name="amount" symbol="currency"/>
+    <field name="amount"/>
 </tree>
diff -r 31bb67e988c7 -r 0d680014600a view/purchase_tree.xml
--- a/view/purchase_tree.xml    Thu Jul 29 09:06:38 2021 +0200
+++ b/view/purchase_tree.xml    Sat Aug 21 09:09:56 2021 +0200
@@ -7,7 +7,7 @@
     <field name="purchase_date"/>
     <field name="party" expand="2"/>
     <field name="warehouse"/>
-    <field name="untaxed_amount" symbol="currency"/>
+    <field name="untaxed_amount"/>
     <field name="state"/>
     <field name="invoice_state"/>
     <field name="shipment_state"/>

Reply via email to