diff --git a/CHANGELOG b/CHANGELOG
index 2aacf018ee..c5540c601d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,4 @@
+* Add customer currency on party
* Add support for Python 3.10
* Remove support for Python 3.6
diff --git a/__init__.py b/__init__.py
index a924298066..8ee5fd6d28 100644
--- a/__init__.py
+++ b/__init__.py
@@ -18,6 +18,7 @@ def register():
sale.SaleLineIgnoredMove,
sale.SaleLineRecreatedMove,
party.Party,
+ party.PartyCustomerCurrency,
party.PartySaleMethod,
product.Configuration,
product.DefaultLeadTime,
diff --git a/party.py b/party.py
index 5b70da2f6c..284cadad8c 100644
--- a/party.py
+++ b/party.py
@@ -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'
diff --git a/party.xml b/party.xml
index 931a8115b7..23475514bd 100644
--- a/party.xml
+++ b/party.xml
@@ -46,5 +46,17 @@ this repository contains the full copyright notices and license terms. -->
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/sale.py b/sale.py
index 7a50b6adca..4d165632b6 100644
--- a/sale.py
+++ b/sale.py
@@ -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):
diff --git a/view/party_form.xml b/view/party_form.xml
index 1d41e7e881..5e477caad0 100644
--- a/view/party_form.xml
+++ b/view/party_form.xml
@@ -11,6 +11,10 @@ this repository contains the full copyright notices and license terms. -->
+
+
+
+