Add default currency on party

issue9305
review290091002
This commit is contained in:
Cédric Krier committed 2022-04-11 21:24:28 +02:00
1 parent d2669aca9a
commit 928e2e6bf7
6 files changed
+52 -7

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
* Add customer currency on party
* Add support for Python 3.10
* Remove support for Python 3.6
+1
View File
@@ -18,6 +18,7 @@ def register():
sale.SaleLineIgnoredMove,
sale.SaleLineRecreatedMove,
party.Party,
party.PartyCustomerCurrency,
party.PartySaleMethod,
product.Configuration,
product.DefaultLeadTime,
+16 -1
View File
@@ -1,7 +1,7 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.i18n import gettext
from trytond.model import ModelSQL, fields
from trytond.model import ModelSQL, ValueMixin, fields
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
from trytond.modules.party.exceptions import EraseError
@@ -9,6 +9,10 @@ from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
from trytond.transaction import Transaction
customer_currency = fields.Many2One(
'currency.currency', "Customer Currency",
help="Default currency for sales to this party.")
def get_sale_methods(field_name):
@classmethod
@@ -33,6 +37,9 @@ class Party(CompanyMultiValueMixin, metaclass=PoolMeta):
"Leave empty to use the default value from the configuration."))
sale_methods = fields.One2Many(
'party.party.sale_method', 'party', "Sale Methods")
customer_currency = fields.MultiValue(customer_currency)
customer_currencies = fields.One2Many(
'party.party.customer_currency', 'party', "Customer Currencies")
@classmethod
def multivalue_model(cls, field):
@@ -76,6 +83,14 @@ class PartySaleMethod(ModelSQL, CompanyValueMixin):
get_sale_shipment_method = get_sale_methods('shipment_method')
class PartyCustomerCurrency(ModelSQL, ValueMixin):
"Party Customer Currency"
__name__ = 'party.party.customer_currency'
party = fields.Many2One(
'party.party', "Party", ondelete='CASCADE', select=True)
customer_currency = customer_currency
class Replace(metaclass=PoolMeta):
__name__ = 'party.replace'
+12
View File
@@ -46,5 +46,17 @@ this repository contains the full copyright notices and license terms. -->
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
</record>
<record model="ir.model.field.access" id="access_party_customer_currency">
<field name="field" search="[('model.model', '=', 'party.party'), ('name', '=', 'customer_currency')]"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="False"/>
</record>
<record model="ir.model.field.access" id="access_party_customer_currency_group_sale">
<field name="field" search="[('model.model', '=', 'party.party'), ('name', '=', 'customer_currency')]"/>
<field name="group" ref="group_sale"/>
<field name="perm_read" eval="True"/>
<field name="perm_write" eval="True"/>
</record>
</data>
</tryton>
+18 -6
View File
@@ -380,10 +380,13 @@ class Sale(
def default_state():
return 'draft'
@staticmethod
def default_currency():
Company = Pool().get('company.company')
company = Transaction().context.get('company')
@classmethod
def default_currency(cls, **pattern):
pool = Pool()
Company = pool.get('company.company')
company = pattern.get('company')
if not company:
company = cls.default_company()
if company:
return Company(company).currency.id
@@ -407,13 +410,19 @@ class Sale(
def default_shipment_state():
return 'none'
@fields.depends('party', 'invoice_party', 'shipment_party', 'payment_term')
@fields.depends(
'company', 'party', 'invoice_party', 'shipment_party', 'payment_term',
'lines')
def on_change_party(self):
if not self.invoice_party:
self.invoice_address = None
if not self.shipment_party:
self.shipment_address = None
self.payment_term = self.default_payment_term()
self.payment_term = self.default_payment_term(
company=self.company.id if self.company else None)
if not self.lines:
self.currency = self.default_currency(
company=self.company.id if self.company else None)
if self.party:
if not self.invoice_party:
self.invoice_address = self.party.address_get(type='invoice')
@@ -429,6 +438,9 @@ class Sale(
self.invoice_method = self.party.sale_invoice_method
else:
self.invoice_method = self.default_invoice_method()
if not self.lines:
if self.party.customer_currency:
self.currency = self.party.customer_currency
@fields.depends('party', 'invoice_party')
def on_change_invoice_party(self):
+4
View File
@@ -11,6 +11,10 @@ this repository contains the full copyright notices and license terms. -->
<field name="sale_invoice_method"/>
<label name="sale_shipment_method"/>
<field name="sale_shipment_method"/>
<label name="customer_currency"/>
<field name="customer_currency"/>
<newline/>
</page>
</xpath>
</data>