diff --git a/account_commission/models/account_move.py b/account_commission/models/account_move.py index 3bad159a8..51e7ff146 100644 --- a/account_commission/models/account_move.py +++ b/account_commission/models/account_move.py @@ -210,8 +210,6 @@ class AccountInvoiceLineAgent(models.Model): ) currency_id = fields.Many2one( related="object_id.currency_id", - readonly=True, - store=True, ) @api.depends( diff --git a/account_commission/models/commission_settlement.py b/account_commission/models/commission_settlement.py index 9727fb4dc..6984def2a 100644 --- a/account_commission/models/commission_settlement.py +++ b/account_commission/models/commission_settlement.py @@ -78,9 +78,6 @@ def action_invoice(self): def _get_invoice_partner(self): return self[0].agent_id - def _get_invoice_currency(self): - return self[0].currency_id - def _prepare_invoice(self, journal, product, date=False): move_form = Form( self.env["account.move"].with_context(default_move_type="in_invoice") @@ -88,10 +85,9 @@ def _prepare_invoice(self, journal, product, date=False): if date: move_form.invoice_date = date partner = self._get_invoice_partner() - currency = self._get_invoice_currency() move_form.partner_id = partner move_form.journal_id = journal - move_form.currency_id = currency + move_form.currency_id = self.currency_id for settlement in self: with move_form.invoice_line_ids.new() as line_form: line_form.product_id = product diff --git a/account_commission/wizards/commission_make_settle.py b/account_commission/wizards/commission_make_settle.py index c4870e325..d2e5c32c5 100644 --- a/account_commission/wizards/commission_make_settle.py +++ b/account_commission/wizards/commission_make_settle.py @@ -14,19 +14,16 @@ class CommissionMakeSettle(models.TransientModel): ondelete={"sale_invoice": "cascade"}, ) - def _get_account_settle_domain(self, agent, date_to_agent): - return [ - ("invoice_date", "<", date_to_agent), - ("agent_id", "=", agent.id), - ("settled", "=", False), - ] - def _get_agent_lines(self, agent, date_to_agent): """Filter sales invoice agent lines for this type of settlement.""" if self.settlement_type != "sale_invoice": return super()._get_agent_lines(agent, date_to_agent) return self.env["account.invoice.line.agent"].search( - self._get_account_settle_domain(agent, date_to_agent), + [ + ("invoice_date", "<", date_to_agent), + ("agent_id", "=", agent.id), + ("settled", "=", False), + ], order="invoice_date", ) diff --git a/commission/wizards/commission_make_settle.py b/commission/wizards/commission_make_settle.py index a1455723f..e3eb8fc6d 100644 --- a/commission/wizards/commission_make_settle.py +++ b/commission/wizards/commission_make_settle.py @@ -82,13 +82,12 @@ def _get_settlement(self, agent, company, currency, sett_from, sett_to): limit=1, ) - def _prepare_settlement_vals(self, agent, company, currency, sett_from, sett_to): + def _prepare_settlement_vals(self, agent, company, sett_from, sett_to): return { "agent_id": agent.id, "date_from": sett_from, "date_to": sett_to, "company_id": company.id, - "currency_id": currency.id, "settlement_type": self.settlement_type, } @@ -152,11 +151,11 @@ def action_settle(self): self._prepare_settlement_vals( agent, line.company_id, - line.currency_id, sett_from, sett_to, ) ) + settlement.currency_id = line.currency_id settlement_ids.append(settlement.id) settlement_line_vals.append( self._prepare_settlement_line_vals(settlement, line)