changeset 67261751bbc3 in modules/sale:default
details: https://hg.tryton.org/modules/sale?cmd=changeset&node=67261751bbc3
description:
        Add monetary field

        issue10598
        review338511002
diffstat:

 product.py                                                   |   3 +-
 sale.py                                                      |  57 +++--------
 sale_reporting.py                                            |  40 +++-----
 view/sale_form.xml                                           |   6 +-
 view/sale_line_form.xml                                      |   4 +-
 view/sale_line_tree.xml                                      |   4 +-
 view/sale_line_tree_sequence.xml                             |   4 +-
 view/sale_reporting_country_subdivision_time_series_list.xml |   2 +-
 view/sale_reporting_country_time_series_list.xml             |   2 +-
 view/sale_reporting_customer_category_list.xml               |   2 +-
 view/sale_reporting_customer_category_time_series_list.xml   |   2 +-
 view/sale_reporting_customer_list.xml                        |   2 +-
 view/sale_reporting_customer_time_series_list.xml            |   2 +-
 view/sale_reporting_product_category_list.xml                |   2 +-
 view/sale_reporting_product_category_time_series_list.xml    |   2 +-
 view/sale_reporting_product_list.xml                         |   2 +-
 view/sale_reporting_product_time_series_list.xml             |   2 +-
 view/sale_reporting_region_tree.xml                          |   2 +-
 view/sale_tree.xml                                           |   2 +-
 19 files changed, 56 insertions(+), 86 deletions(-)

diffs (421 lines):

diff -r 5867435a65cf -r 67261751bbc3 product.py
--- a/product.py        Fri Aug 06 09:51:08 2021 +0200
+++ b/product.py        Sat Aug 21 09:09:56 2021 +0200
@@ -7,6 +7,7 @@
 from trytond.pool import Pool, PoolMeta
 from trytond.transaction import Transaction
 from trytond.modules.company.model import CompanyValueMixin
+from trytond.modules.currency.fields import Monetary
 from trytond.modules.product import price_digits
 
 
@@ -102,7 +103,7 @@
 class Product(metaclass=PoolMeta):
     __name__ = 'product.product'
 
-    sale_price_uom = fields.Function(fields.Numeric(
+    sale_price_uom = fields.Function(Monetary(
             "Sale Price", digits=price_digits), 'get_sale_price_uom')
 
     @classmethod
diff -r 5867435a65cf -r 67261751bbc3 sale.py
--- a/sale.py   Fri Aug 06 09:51:08 2021 +0200
+++ b/sale.py   Sat Aug 21 09:09:56 2021 +0200
@@ -23,6 +23,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 (
@@ -171,34 +172,23 @@
                 | (Eval('lines', [0]) & Eval('currency', 0))),
             },
         depends=['state'])
-    currency_digits = fields.Function(fields.Integer('Currency Digits'),
-        'on_change_with_currency_digits')
     lines = fields.One2Many('sale.line', 'sale', 'Lines', states={
             'readonly': Eval('state') != 'draft',
             },
         depends=['party', 'state'])
     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)),
-        readonly=True,
-        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)),
-        readonly=True,
-        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)),
-        readonly=True,
-        depends=['currency_digits'])
+    untaxed_amount = fields.Function(Monetary(
+            "Untaxed", digits='currency', currency='currency'), 'get_amount')
+    untaxed_amount_cache = fields.Numeric(
+        "Untaxed Cache", digits='currency', readonly=True)
+    tax_amount = fields.Function(Monetary(
+            "Tax", digits='currency', currency='currency'), 'get_amount')
+    tax_amount_cache = fields.Numeric(
+        "Tax Cache", digits='currency', readonly=True)
+    total_amount = fields.Function(Monetary(
+            "Total", digits='currency', currency='currency'), 'get_amount')
+    total_amount_cache = fields.Numeric(
+        "Total Cache", digits='currency', readonly=True)
     invoice_method = fields.Selection([
             ('manual', 'Manual'),
             ('order', 'On Order Processed'),
@@ -410,14 +400,6 @@
         if company:
             return Company(company).currency.id
 
-    @staticmethod
-    def default_currency_digits():
-        Company = Pool().get('company.company')
-        company = Transaction().context.get('company')
-        if company:
-            return Company(company).currency.digits
-        return 2
-
     @classmethod
     def default_invoice_method(cls, **pattern):
         Config = Pool().get('sale.configuration')
@@ -469,12 +451,6 @@
         elif self.party:
             self.shipment_address = self.party.address_get(type='delivery')
 
-    @fields.depends('currency')
-    def on_change_with_currency_digits(self, name=None):
-        if self.currency:
-            return self.currency.digits
-        return 2
-
     @fields.depends('party', 'company')
     def _get_tax_context(self):
         context = {}
@@ -1126,14 +1102,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", digits=price_digits, currency='currency',
         states={
             'invisible': Eval('type') != 'line',
             'required': Eval('type') == 'line',
             'readonly': Eval('sale_state') != 'draft'
             }, depends=['type', 'sale_state'])
-    amount = fields.Function(fields.Numeric('Amount',
-            digits=(16, Eval('_parent_sale', {}).get('currency_digits', 2)),
+    amount = fields.Function(Monetary(
+            "Amount", digits='currency', currency='currency',
             states={
                 'invisible': ~Eval('type').in_(['line', 'subtotal']),
                 },
diff -r 5867435a65cf -r 67261751bbc3 sale_reporting.py
--- a/sale_reporting.py Fri Aug 06 09:51:08 2021 +0200
+++ b/sale_reporting.py Sat Aug 21 09:09:56 2021 +0200
@@ -21,6 +21,8 @@
 from trytond.wizard import Wizard, StateTransition, StateAction
 from trytond.i18n import lazy_gettext
 
+from trytond.modules.currency.fields import Monetary
+
 
 def pairwise(iterable):
     a, b = tee(iterable)
@@ -34,10 +36,9 @@
         'company.company', lazy_gettext("sale.msg_sale_reporting_company"))
     number = fields.Integer(lazy_gettext("sale.msg_sale_reporting_number"),
         help=lazy_gettext("sale.msg_sale_reporting_number_help"))
-    revenue = fields.Numeric(
+    revenue = Monetary(
         lazy_gettext("sale.msg_sale_reporting_revenue"),
-        digits=(16, Eval('currency_digits', 2)),
-        depends=['currency_digits'])
+        digits='currency', currency='currency')
     revenue_trend = fields.Function(
         fields.Char(lazy_gettext("sale.msg_sale_reporting_revenue_trend")),
         'get_trend')
@@ -47,10 +48,6 @@
             'currency.currency',
             lazy_gettext("sale.msg_sale_reporting_currency")),
         'get_currency')
-    currency_digits = fields.Function(
-        fields.Integer(
-            lazy_gettext("sale.msg_sale_reporting_currency_digits")),
-        'get_currency_digits')
 
     @classmethod
     def table_query(cls):
@@ -180,9 +177,6 @@
     def get_currency(self, name):
         return self.company.currency.id
 
-    def get_currency_digits(self, name):
-        return self.company.currency.digits
-
 
 class AbstractTimeseries(Abstract):
 
@@ -407,12 +401,11 @@
     parent = fields.Many2One('sale.reporting.customer.category.tree', "Parent")
     children = fields.One2Many(
         'sale.reporting.customer.category.tree', 'parent', "Children")
-    revenue = fields.Function(
-        fields.Numeric("Revenue", digits=(16, Eval('currency_digits', 2)),
-            depends=['currency_digits']), 'get_total')
+    revenue = fields.Function(Monetary(
+            "Revenue", digits='currency', currency='currency'), 'get_total')
 
-    currency_digits = fields.Function(
-        fields.Integer("Currency Digits"), 'get_currency_digits')
+    currency = fields.Function(fields.Many2One(
+            'currency.currency', "Currency"), 'get_currency')
 
     @classmethod
     def __setup__(cls):
@@ -506,12 +499,12 @@
             leafs = next_leafs
         return result
 
-    def get_currency_digits(self, name):
+    def get_currency(self, name):
         pool = Pool()
         Company = pool.get('company.company')
         company = Transaction().context.get('company')
         if company:
-            return Company(company).currency.digits
+            return Company(company).currency.id
 
 
 class ProductMixin(object):
@@ -667,12 +660,11 @@
     parent = fields.Many2One('sale.reporting.product.category.tree', "Parent")
     children = fields.One2Many(
         'sale.reporting.product.category.tree', 'parent', "Children")
-    revenue = fields.Function(
-        fields.Numeric("Revenue", digits=(16, Eval('currency_digits', 2)),
-            depends=['currency_digits']), 'get_total')
+    revenue = fields.Function(Monetary(
+            "Revenue", digits='currency'), 'get_total')
 
-    currency_digits = fields.Function(
-        fields.Integer("Currency Digits"), 'get_currency_digits')
+    currency = fields.Function(fields.Many2One(
+            'currency.currency', "Currency"), 'get_currency')
 
     @classmethod
     def __setup__(cls):
@@ -765,12 +757,12 @@
             leafs = next_leafs
         return result
 
-    def get_currency_digits(self, name):
+    def get_currency(self, name):
         pool = Pool()
         Company = pool.get('company.company')
         company = Transaction().context.get('company')
         if company:
-            return Company(company).currency.digits
+            return Company(company).currency.id
 
 
 class CountryMixin(object):
diff -r 5867435a65cf -r 67261751bbc3 view/sale_form.xml
--- a/view/sale_form.xml        Fri Aug 06 09:51:08 2021 +0200
+++ b/view/sale_form.xml        Sat Aug 21 09:09:56 2021 +0200
@@ -48,11 +48,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="other">
diff -r 5867435a65cf -r 67261751bbc3 view/sale_line_form.xml
--- a/view/sale_line_form.xml   Fri Aug 06 09:51:08 2021 +0200
+++ b/view/sale_line_form.xml   Sat Aug 21 09:09:56 2021 +0200
@@ -19,9 +19,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 name="shipping_date"/>
             <field name="shipping_date"/>
             <separator name="description" colspan="4"/>
diff -r 5867435a65cf -r 67261751bbc3 view/sale_line_tree.xml
--- a/view/sale_line_tree.xml   Fri Aug 06 09:51:08 2021 +0200
+++ b/view/sale_line_tree.xml   Sat Aug 21 09:09:56 2021 +0200
@@ -7,7 +7,7 @@
     <field name="product" 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 5867435a65cf -r 67261751bbc3 view/sale_line_tree_sequence.xml
--- a/view/sale_line_tree_sequence.xml  Fri Aug 06 09:51:08 2021 +0200
+++ b/view/sale_line_tree_sequence.xml  Sat Aug 21 09:09:56 2021 +0200
@@ -7,7 +7,7 @@
     <field name="product" 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 5867435a65cf -r 67261751bbc3 
view/sale_reporting_country_subdivision_time_series_list.xml
--- a/view/sale_reporting_country_subdivision_time_series_list.xml      Fri Aug 
06 09:51:08 2021 +0200
+++ b/view/sale_reporting_country_subdivision_time_series_list.xml      Sat Aug 
21 09:09:56 2021 +0200
@@ -4,5 +4,5 @@
 <tree>
     <field name="date"/>
     <field name="number"/>
-    <field name="revenue" symbol="currency"/>
+    <field name="revenue"/>
 </tree>
diff -r 5867435a65cf -r 67261751bbc3 
view/sale_reporting_country_time_series_list.xml
--- a/view/sale_reporting_country_time_series_list.xml  Fri Aug 06 09:51:08 
2021 +0200
+++ b/view/sale_reporting_country_time_series_list.xml  Sat Aug 21 09:09:56 
2021 +0200
@@ -4,5 +4,5 @@
 <tree>
     <field name="date"/>
     <field name="number"/>
-    <field name="revenue" symbol="currency"/>
+    <field name="revenue"/>
 </tree>
diff -r 5867435a65cf -r 67261751bbc3 
view/sale_reporting_customer_category_list.xml
--- a/view/sale_reporting_customer_category_list.xml    Fri Aug 06 09:51:08 
2021 +0200
+++ b/view/sale_reporting_customer_category_list.xml    Sat Aug 21 09:09:56 
2021 +0200
@@ -4,6 +4,6 @@
 <tree keyword_open="1">
     <field name="category" expand="1"/>
     <field name="number"/>
-    <field name="revenue" symbol="currency"/>
+    <field name="revenue"/>
     <field name="revenue_trend" expand="1"/>
 </tree>
diff -r 5867435a65cf -r 67261751bbc3 
view/sale_reporting_customer_category_time_series_list.xml
--- a/view/sale_reporting_customer_category_time_series_list.xml        Fri Aug 
06 09:51:08 2021 +0200
+++ b/view/sale_reporting_customer_category_time_series_list.xml        Sat Aug 
21 09:09:56 2021 +0200
@@ -4,5 +4,5 @@
 <tree>
     <field name="date"/>
     <field name="number"/>
-    <field name="revenue" symbol="currency"/>
+    <field name="revenue"/>
 </tree>
diff -r 5867435a65cf -r 67261751bbc3 view/sale_reporting_customer_list.xml
--- a/view/sale_reporting_customer_list.xml     Fri Aug 06 09:51:08 2021 +0200
+++ b/view/sale_reporting_customer_list.xml     Sat Aug 21 09:09:56 2021 +0200
@@ -4,6 +4,6 @@
 <tree keyword_open="1">
     <field name="customer" expand="1"/>
     <field name="number"/>
-    <field name="revenue" symbol="currency"/>
+    <field name="revenue"/>
     <field name="revenue_trend" expand="1"/>
 </tree>
diff -r 5867435a65cf -r 67261751bbc3 
view/sale_reporting_customer_time_series_list.xml
--- a/view/sale_reporting_customer_time_series_list.xml Fri Aug 06 09:51:08 
2021 +0200
+++ b/view/sale_reporting_customer_time_series_list.xml Sat Aug 21 09:09:56 
2021 +0200
@@ -4,5 +4,5 @@
 <tree>
     <field name="date"/>
     <field name="number"/>
-    <field name="revenue" symbol="currency"/>
+    <field name="revenue"/>
 </tree>
diff -r 5867435a65cf -r 67261751bbc3 
view/sale_reporting_product_category_list.xml
--- a/view/sale_reporting_product_category_list.xml     Fri Aug 06 09:51:08 
2021 +0200
+++ b/view/sale_reporting_product_category_list.xml     Sat Aug 21 09:09:56 
2021 +0200
@@ -4,6 +4,6 @@
 <tree keyword_open="1">
     <field name="category" expand="1"/>
     <field name="number"/>
-    <field name="revenue" symbol="currency"/>
+    <field name="revenue"/>
     <field name="revenue_trend" expand="1"/>
 </tree>
diff -r 5867435a65cf -r 67261751bbc3 
view/sale_reporting_product_category_time_series_list.xml
--- a/view/sale_reporting_product_category_time_series_list.xml Fri Aug 06 
09:51:08 2021 +0200
+++ b/view/sale_reporting_product_category_time_series_list.xml Sat Aug 21 
09:09:56 2021 +0200
@@ -4,5 +4,5 @@
 <tree>
     <field name="date"/>
     <field name="number"/>
-    <field name="revenue" symbol="currency"/>
+    <field name="revenue"/>
 </tree>
diff -r 5867435a65cf -r 67261751bbc3 view/sale_reporting_product_list.xml
--- a/view/sale_reporting_product_list.xml      Fri Aug 06 09:51:08 2021 +0200
+++ b/view/sale_reporting_product_list.xml      Sat Aug 21 09:09:56 2021 +0200
@@ -4,6 +4,6 @@
 <tree keyword_open="1">
     <field name="product" expand="1"/>
     <field name="number"/>
-    <field name="revenue" symbol="currency"/>
+    <field name="revenue"/>
     <field name="revenue_trend" expand="1"/>
 </tree>
diff -r 5867435a65cf -r 67261751bbc3 
view/sale_reporting_product_time_series_list.xml
--- a/view/sale_reporting_product_time_series_list.xml  Fri Aug 06 09:51:08 
2021 +0200
+++ b/view/sale_reporting_product_time_series_list.xml  Sat Aug 21 09:09:56 
2021 +0200
@@ -4,5 +4,5 @@
 <tree>
     <field name="date"/>
     <field name="number"/>
-    <field name="revenue" symbol="currency"/>
+    <field name="revenue"/>
 </tree>
diff -r 5867435a65cf -r 67261751bbc3 view/sale_reporting_region_tree.xml
--- a/view/sale_reporting_region_tree.xml       Fri Aug 06 09:51:08 2021 +0200
+++ b/view/sale_reporting_region_tree.xml       Sat Aug 21 09:09:56 2021 +0200
@@ -4,6 +4,6 @@
 <tree keyword_open="1">
     <field name="region" expand="1"/>
     <field name="number"/>
-    <field name="revenue" symbol="currency"/>
+    <field name="revenue"/>
     <field name="revenue_trend" expand="1"/>
 </tree>
diff -r 5867435a65cf -r 67261751bbc3 view/sale_tree.xml
--- a/view/sale_tree.xml        Fri Aug 06 09:51:08 2021 +0200
+++ b/view/sale_tree.xml        Sat Aug 21 09:09:56 2021 +0200
@@ -7,7 +7,7 @@
     <field name="sale_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