Skip to content

Commit

Permalink
[FIXUP] improvements based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
jguenat committed Nov 24, 2023
1 parent 5defedd commit 174e144
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
2 changes: 0 additions & 2 deletions account_commission/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,6 @@ class AccountInvoiceLineAgent(models.Model):
)
currency_id = fields.Many2one(
related="object_id.currency_id",
readonly=True,
store=True,
)

@api.depends(
Expand Down
6 changes: 1 addition & 5 deletions account_commission/models/commission_settlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,16 @@ 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")
)
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
Expand Down
13 changes: 5 additions & 8 deletions account_commission/wizards/commission_make_settle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
5 changes: 2 additions & 3 deletions commission/wizards/commission_make_settle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 174e144

Please sign in to comment.