diff options
| author | Lucas Perais (lpe) <lpe@odoo.com> | 2018-10-25 09:10:46 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2018-11-14 15:14:36 +0000 |
| commit | 50e5f73b4e2461982e5312ff0707e9d770b09f0f (patch) | |
| tree | e12603cdc66efa4e9c0eeee7705e4760352689cb /odoo/fields.py | |
| parent | c41902a21c50e0accc1b9d6bfa60bce8ecbb5955 (diff) | |
[FIX] fields, test_new_api: monetary related custom
This commit allows for not copying the currency_field attribute
of a monetary field when the monetary field is related,
and when the currency_field attribute is not explicit
Before this commit, the currency_field attribute on the related monetary
was set as the one on the distant model
After this commit, the currency_field attribute takes the field on the
current model
Though the test may appear like an incoherent use case,
it is on the contrary totally legit, as web_studio allows it
OPW 1903113
closes odoo/odoo#28144
Diffstat (limited to 'odoo/fields.py')
| -rw-r--r-- | odoo/fields.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/odoo/fields.py b/odoo/fields.py index a146a1bfa07..00923886d0a 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -1276,11 +1276,9 @@ class Monetary(Field): def __init__(self, string=Default, currency_field=Default, **kwargs): super(Monetary, self).__init__(string=string, currency_field=currency_field, **kwargs) - _related_currency_field = property(attrgetter('currency_field')) _description_currency_field = property(attrgetter('currency_field')) - def _setup_regular_full(self, model): - super(Monetary, self)._setup_regular_full(model) + def _setup_currency_field(self, model): if not self.currency_field: # pick a default, trying in order: 'currency_id', 'x_currency_id' if 'currency_id' in model._fields: @@ -1290,6 +1288,16 @@ class Monetary(Field): assert self.currency_field in model._fields, \ "Field %s with unknown currency_field %r" % (self, self.currency_field) + def _setup_regular_full(self, model): + super(Monetary, self)._setup_regular_full(model) + self._setup_currency_field(model) + + def _setup_related_full(self, model): + super(Monetary, self)._setup_related_full(model) + if self.inherited: + self.currency_field = self.related_field.currency_field + self._setup_currency_field(model) + def convert_to_column(self, value, record, values=None, validate=True): # retrieve currency from values or record if values and self.currency_field in values: |
