-
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DO NOT MERGE: sale_commission_partial_settlement: major refactor
- Loading branch information
Showing
13 changed files
with
244 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 53 additions & 10 deletions
63
sale_commission_partial_settlement/models/account_invoice_line_agent_partial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,71 @@ | ||
# Copyright 2023 Nextev | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
from odoo import api, fields, models | ||
|
||
|
||
class AccountInvoiceLineAgentPartial(models.Model): | ||
_name = "account.invoice.line.agent.partial" | ||
_description = "Partial agent commissions" | ||
_description = "Partial agent commissions. " | ||
"Tracks the expected commissions." | ||
|
||
move_line_id = fields.Many2one( | ||
"account.move.line", | ||
required=True, # TODO: migration? Probably cannot enforce | ||
ondelete="cascade", | ||
) | ||
invoice_line_agent_id = fields.Many2one( | ||
"account.invoice.line.agent", required=True, ondelete="cascade" | ||
) | ||
# logically a One2one | ||
agent_line = fields.Many2many( | ||
comodel_name="sale.commission.settlement.line", | ||
relation="settlement_agent_line_partial_rel", | ||
column1="agent_line_partial_id", | ||
column2="settlement_id", | ||
copy=False, | ||
settlement_line_partial_ids = fields.One2many( | ||
"sale.commission.settlement.line.partial", | ||
"invoice_agent_partial_id", | ||
) | ||
account_partial_reconcile_id = fields.Many2one("account.partial.reconcile") | ||
account_partial_reconcile_id = fields.Many2one( | ||
"account.partial.reconcile" | ||
) # TODO: Remove | ||
amount = fields.Monetary( | ||
compute="_compute_amount", | ||
store=True, | ||
string="Commission Amount", | ||
) | ||
currency_id = fields.Many2one( | ||
related="invoice_line_agent_id.currency_id", | ||
) | ||
settled_amount = fields.Monetary( | ||
compute="_compute_settled_amount", | ||
store=True, | ||
) | ||
is_settled = fields.Boolean( | ||
compute="_compute_settled_amount", store=True, string="Fully settled" | ||
) | ||
|
||
move_line_balance = fields.Monetary(related="move_line_id.balance") | ||
date_maturity = fields.Date(related="move_line_id.date_maturity") | ||
agent_id = fields.Many2one(related="invoice_line_agent_id.agent_id") | ||
invoice_date = fields.Date(related="invoice_line_agent_id.invoice_date") | ||
|
||
@api.depends( | ||
"settlement_line_partial_ids.amount", | ||
"settlement_line_partial_ids.canceled", | ||
) | ||
def _compute_settled_amount(self): | ||
for rec in self: | ||
# TODO: handle different currencies | ||
rec.settled_amount = sum( | ||
x.amount for x in rec.settlement_line_partial_ids if not x.canceled | ||
) | ||
rec.is_settled = rec.currency_id.is_zero(rec.settled_amount - rec.amount) | ||
|
||
@api.depends( | ||
"move_line_id.balance", | ||
"move_line_id.move_id.amount_total", | ||
"invoice_line_agent_id.amount", | ||
) | ||
def _compute_amount(self): | ||
for rec in self: | ||
rec.amount = ( | ||
rec.move_line_id.balance | ||
/ rec.move_line_id.move_id.amount_total | ||
* rec.invoice_line_agent_id.amount | ||
) |
36 changes: 18 additions & 18 deletions
36
sale_commission_partial_settlement/models/account_partial_reconcile.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
from odoo import api, fields, models | ||
from odoo import fields, models | ||
|
||
|
||
class AccountPartialReconcile(models.Model): | ||
_inherit = "account.partial.reconcile" | ||
|
||
# Logically a One2one | ||
account_invoice_line_agent_partial_ids = fields.One2many( | ||
"account.invoice.line.agent.partial", "account_partial_reconcile_id" | ||
) | ||
partial_commission_settled = fields.Boolean( | ||
compute="_compute_partial_commission_settled", store=True | ||
) | ||
) # TODO: Remove? | ||
# partial_commission_settled = fields.Boolean( | ||
# compute="_compute_partial_commission_settled", store=True | ||
# ) | ||
|
||
@api.depends( | ||
"account_invoice_line_agent_partial_ids", | ||
"account_invoice_line_agent_partial_ids.agent_line.settlement_id.state", | ||
) | ||
def _compute_partial_commission_settled(self): | ||
for rec in self: | ||
rec.partial_commission_settled = any( | ||
settlement.state != "cancel" | ||
for settlement in rec.mapped( | ||
"account_invoice_line_agent_partial_ids.agent_line.settlement_id" | ||
) | ||
) | ||
# APR can't tell if every agent was settled! | ||
# @api.depends( | ||
# "account_invoice_line_agent_partial_ids", | ||
# "account_invoice_line_agent_partial_ids.agent_line.settlement_id.state", | ||
# ) | ||
# def _compute_partial_commission_settled(self): | ||
# for rec in self: | ||
# rec.partial_commission_settled = any( | ||
# settlement.state != "cancel" | ||
# for settlement in rec.mapped( | ||
# "account_invoice_line_agent_partial_ids.agent_line.settlement_id" | ||
# ) | ||
# ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
sale_commission_partial_settlement/models/sale_commission_settlement_line_partial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from odoo import api, fields, models | ||
|
||
|
||
class SettlementLinePartial(models.Model): | ||
_name = "sale.commission.settlement.line.partial" | ||
_description = "Partial settlements. " | ||
"Tracks the effective settled amounts relative to the expected." | ||
|
||
settlement_line_id = fields.Many2one( | ||
comodel_name="sale.commission.settlement.line", | ||
ondelete="cascade", | ||
) | ||
invoice_agent_partial_id = fields.Many2one( | ||
comodel_name="account.invoice.line.agent.partial", | ||
required=True, | ||
) | ||
agent_id = fields.Many2one(related="invoice_agent_partial_id.agent_id") | ||
invoice_date = fields.Date(related="invoice_agent_partial_id.invoice_date") | ||
amount = fields.Monetary(readonly=True) | ||
currency_id = fields.Many2one( | ||
related="settlement_line_id.currency_id", | ||
) | ||
# date_maturity = fields.Date() TODO: move to ooops module | ||
canceled = fields.Boolean(compute="_compute_canceled", store=True) | ||
|
||
@api.depends("settlement_line_id.settlement_id.state") | ||
def _compute_canceled(self): | ||
for rec in self: | ||
rec.canceled = rec.settlement_line_id.settlement_id.state == "cancel" |
2 changes: 2 additions & 0 deletions
2
sale_commission_partial_settlement/security/ir.model.access.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_account_invoice_line_agent_partial,access_account_invoice_line_agent_partial,model_account_invoice_line_agent_partial,sales_team.group_sale_salesman,1,1,1,1 | ||
access_account_invoice_line_agent_partial_user,access_account_invoice_line_agent_partial_user,model_account_invoice_line_agent_partial,base.group_user,1,0,0,0 | ||
access_sale_commission_settlement_line_partial,access_sale_commission_settlement_line_partial,model_sale_commission_settlement_line_partial,sales_team.group_sale_salesman,1,1,1,1 | ||
access_sale_commission_settlement_line_partial_user,access_sale_commission_settlement_line_partial_user,model_sale_commission_settlement_line_partial,base.group_user,1,0,0,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
sale_commission_partial_settlement/views/account_invoice_line_agent_partial_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="invoice_line_agent_partial_tree" model="ir.ui.view"> | ||
<field name="model">account.invoice.line.agent.partial</field> | ||
<field name="arch" type="xml"> | ||
<tree> | ||
<field name="agent_id" /> | ||
<field name="amount" /> | ||
<field name="currency_id" invisible="1" /> | ||
<field name="date_maturity" /> | ||
<field name="settled_amount" /> | ||
<field name="is_settled" /> | ||
<!-- Button to see scslp --> | ||
</tree> | ||
</field> | ||
</record> | ||
</odoo> |
32 changes: 32 additions & 0 deletions
32
sale_commission_partial_settlement/views/account_invoice_line_agent_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="invoice_line_agent_tree" model="ir.ui.view"> | ||
<field name="model">account.invoice.line.agent</field> | ||
<field name="inherit_id" ref="sale_commission.invoice_line_agent_tree" /> | ||
<field name="arch" type="xml"> | ||
<field name="amount" position="after"> | ||
<field name="payment_amount_type" invisible="1" /> | ||
<button | ||
name="action_see_partial_commission_forecast" | ||
icon="fa-list" | ||
attrs="{'invisible': [ | ||
('payment_amount_type', '!=', 'paid'), | ||
] | ||
}" | ||
type="object" | ||
/> | ||
</field> | ||
</field> | ||
</record> | ||
<record id="view_sale_commission_mixin_agent_only" model="ir.ui.view"> | ||
<field name="model">account.invoice.line.agent</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<field name="invoice_line_agent_partial_ids" readonly="1" /> | ||
<footer> | ||
<button string="Close" class="oe_highlight" special="cancel" /> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
</odoo> |
Oops, something went wrong.