From 5f3d8902a3e8526f5e0fa722ef0980ea18bc092e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 9 Oct 2022 18:48:58 +0200 Subject: [PATCH] Allow creating manual commission issue11735 review411801003 --- CHANGELOG | 1 + commission.py | 18 ++++++++++++++++-- invoice.py | 1 + view/commission_form.xml | 7 ++++--- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index dbcdbddfe6..38b60f7009 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Allow creating manual commission * Include commission to stock margin report Version 6.4.0 - 2022-05-02 diff --git a/commission.py b/commission.py index 84f0fecd8f..521b2387a2 100644 --- a/commission.py +++ b/commission.py @@ -333,8 +333,8 @@ class Commission(ModelSQL, ModelView): _readonly_states = { 'readonly': Bool(Eval('invoice_line')), } - origin = fields.Reference('Origin', selection='get_origin', select=True, - readonly=True, + origin = fields.Reference( + "Origin", selection='get_origin', select=True, states=_readonly_states, help="The source of the commission.") date = fields.Date('Date', select=True, states=_readonly_states, help="When the commission is due.") @@ -392,6 +392,20 @@ class Commission(ModelSQL, ModelView): models = cls._get_origin() return [(None, '')] + [(m, get_name(m)) for m in models] + @fields.depends('agent', 'origin', 'base_amount') + def on_change_with_base_amount(self): + pool = Pool() + InvoiceLine = pool.get('account.invoice.line') + Currency = pool.get('currency.currency') + if (self.agent + and isinstance(self.origin, InvoiceLine) + and self.origin.id is not None + and self.origin.id >= 0 + and self.base_amount is None): + return Currency.compute( + self.origin.invoice.currency, self.origin.amount, + self.agent.currency, round=False) + @fields.depends('agent') def on_change_with_currency(self, name=None): if self.agent: diff --git a/invoice.py b/invoice.py index 9681c20eac..9b8efa13c0 100644 --- a/invoice.py +++ b/invoice.py @@ -137,6 +137,7 @@ class InvoiceLine(metaclass=PoolMeta): 'invisible': If(Bool(Eval('_parent_invoice')), Eval('_parent_invoice', {}).get('type') == 'in', Eval('invoice_type') == 'in'), + 'readonly': Eval('invoice_state') != 'draft', }, help="The principal who pays a commission for the invoice line.") commissions = fields.One2Many('commission', 'origin', 'Commissions', diff --git a/view/commission_form.xml b/view/commission_form.xml index a4c70c34de..4bac0da94b 100644 --- a/view/commission_form.xml +++ b/view/commission_form.xml @@ -11,14 +11,15 @@ this repository contains the full copyright notices and license terms. -->