Skip to content

Commit

Permalink
[MIG] tg_sale_commission: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhatk0k3 committed Oct 14, 2024
1 parent 2f5dfcc commit fceabeb
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 50 deletions.
1 change: 1 addition & 0 deletions tg_sale_commission/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
"views/res_partner_views.xml",
"views/sale_affiliate_views.xml",
],
"test_tags": "-sale_commission",
"demo": [],
}
9 changes: 6 additions & 3 deletions tg_sale_commission/models/sale_affiliate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ class SaleAffiliate(models.Model):
partner_id = fields.Many2one("res.partner", domain="[('agent', '=', True)]")
bill_count = fields.Integer(compute="_compute_bill_count")
commission_id = fields.Many2one(
"sale.commission",
"commission",
related="partner_id.commission_id",
store=False,
readonly=False,
)

def _get_bill_dict(self):
partner_ids = self.mapped("partner_id").ids
if not partner_ids:
return {}
self.env.cr.execute(
"""
SELECT partner_id, array_agg(id)
Expand All @@ -23,13 +26,13 @@ def _get_bill_dict(self):
FROM account_move_line
WHERE settlement_id IN (
SELECT id
FROM sale_commission_settlement
FROM commission_settlement
WHERE agent_id IN %s
)
)
GROUP BY partner_id
""",
[tuple(self.mapped("partner_id").ids)],
[tuple(partner_ids)],
)

return {row[0]: row[1] for row in self.env.cr.fetchall()}
Expand Down
8 changes: 4 additions & 4 deletions tg_sale_commission/models/settlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class Settlement(models.Model):
_inherit = "sale.commission.settlement"
_inherit = "commission.settlement"

def name_get(self):
res = []
Expand All @@ -18,12 +18,12 @@ def name_get(self):


class SettlementLine(models.Model):
_inherit = "sale.commission.settlement.line"
_inherit = "commission.settlement.line"

@api.constrains("settlement_id", "agent_line")
@api.constrains("settlement_id", "invoice_agent_line_id")
def _check_company(self):
for record in self:
for line in record.agent_line:
for line in record.invoice_agent_line_id:
if (
line.company_id != record.company_id
and line.company_id.commission_settlement_company
Expand Down
25 changes: 15 additions & 10 deletions tg_sale_commission/tests/test_sale_commission.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def setUpClass(cls):
"company_type": "company",
}
)
cls.agent_monthly_paid = cls.env["res.partner"].create(
{"name": "Agent Monthly Paid", "is_company": False, "agent": True}
)
cls.company2 = cls.env["res.company"].create(
{
"partner_id": company_partner.id,
Expand All @@ -31,7 +34,7 @@ def setUpClass(cls):
cls.agent_quaterly,
cls.agent_semi,
cls.agent_annual,
cls.env.ref("sale_commission.res_partner_pritesh_sale_agent"),
cls.env.ref("commission.res_partner_pritesh_sale_agent"),
):
cls.env["sale.affiliate"].create(
{
Expand Down Expand Up @@ -84,23 +87,25 @@ def test_biweekly_other_company(self):
commission = self.commission_net_invoice
sale_order = self._create_sale_order(agent, commission)
sale_order.action_confirm()
invoice = self._invoice_sale_order(sale_order, date="2022-01-01")
invoice = self._create_invoice(agent, commission)
invoice.invoice_date = "2022-01-01"
invoice.date = "2022-01-01"
invoice.action_post()
sale_order2 = self._create_sale_order(agent, commission)
sale_order2.action_confirm()
invoice2 = self._invoice_sale_order(sale_order2, date="2022-01-16")
invoice2 = self._create_invoice(agent, commission, date="2022-01-16")
invoice2.invoice_date = "2022-01-16"
invoice2.date = "2022-01-16"
invoice2.action_post()
sale_order3 = self._create_sale_order(agent, commission)
sale_order3.action_confirm()
invoice3 = self._invoice_sale_order(sale_order3, date="2022-01-31")
invoice3 = self._create_invoice(agent, commission, date="2022-01-31")
invoice3.invoice_date = "2022-01-31"
invoice3.date = "2022-01-31"
invoice3.action_post()
self._settle_agent(agent=self.agent_biweekly, date="2022-02-01")
self._settle_agent_invoice(agent=self.agent_biweekly, date="2022-02-01")
settlements = self.settle_model.search(
[("agent_id", "=", self.agent_biweekly.id)]
)
self.assertEqual(len(settlements), 2)
self.assertEqual(settlements.mapped("company_id"), self.company2)

def test_commission_propagation(self):
def test_sale_commission_propagation(self):
# propagation feature is disabled
pass
10 changes: 5 additions & 5 deletions tg_sale_commission/views/menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,37 @@
<menuitem
id="menu_agents"
parent="menu_sale_commissions_management"
action="sale_commission.action_agent_form"
action="commission.action_agent_form"
sequence="10"
/>

<menuitem
name="Commission types"
id="menu_sale_commissions_types"
parent="menu_sale_commissions_management"
action="sale_commission.action_commission"
action="commission.action_commission"
sequence="20"
/>

<menuitem
name="Settlements"
id="menu_settlements"
parent="menu_sale_commissions_management"
action="sale_commission.action_settle_commission"
action="commission.action_commission_settlement"
sequence="40"
/>

<menuitem
id="menu_agents_settlement"
parent="menu_sale_commissions_management"
action="sale_commission.action_agents_settlement"
action="commission.action_agents_settlement"
sequence="50"
/>

<menuitem
id="menu_commission_make_invoices"
parent="menu_sale_commissions_management"
sequence="60"
action="sale_commission.action_commission_make_invoices"
action="account_commission.action_commission_make_invoices"
/>
</odoo>
17 changes: 4 additions & 13 deletions tg_sale_commission/views/res_partner_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@
<record id="partner_view_form" model="ir.ui.view">
<field name="name">res.partner.form.agent.tg</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="sale_commission.view_partner_form_agent" />
<field name="inherit_id" ref="commission.view_partner_form_agent" />
<field name="arch" type="xml">
<xpath expr="//field[@name='agent_ids']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath
expr="//page[@name='sales_purchases']//field[@name='agent']"
position="attributes"
>
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//page[@name='agent_information']" position="attributes">
<attribute name="attrs" />
</xpath>
<xpath expr="//page[@name='agent_information']/group" position="before">
<group>
<field name="agent" />
Expand All @@ -26,9 +17,9 @@
expr="//page[@name='agent_information']/group[2]"
position="attributes"
>
<attribute
name="attrs"
>{'invisible': [('agent', '=', False)]}</attribute>
<attribute name="invisible">
agent == False
</attribute>
</xpath>
</field>
</record>
Expand Down
24 changes: 12 additions & 12 deletions tg_sale_commission/views/sale_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
<field name="ui_hide_commission_fields" invisible="1" />
</xpath>
<xpath expr="//button[@name='button_edit_agents']" position="attributes">
<attribute
name="attrs"
>{'invisible': ['|', '|', ('commission_free', '=', True), ('invoice_lines', '!=', []), ('parent.ui_hide_commission_fields', '=', True)]}</attribute>
<attribute name="invisible">
commission_free == True or invoice_lines != [] or parent.ui_hide_commission_fields == True
</attribute>
</xpath>
<xpath expr="//field[@name='commission_status']" position="attributes">
<attribute
name="attrs"
>{'column_invisible': [('parent.ui_hide_commission_fields', '=', True)]}</attribute>
<attribute name="column_invisible">
parent.ui_hide_commission_fields == True
</attribute>
</xpath>
<xpath expr="//field[@name='commission_total']" position="attributes">
<attribute
name="attrs"
>{'invisible': [('ui_hide_commission_fields', '=', True)]}</attribute>
<attribute name="invisible">
ui_hide_commission_fields == True
</attribute>
</xpath>
<xpath
expr="//group[@name='group_recompute_commission']"
position="attributes"
>
<attribute
name="attrs"
>{'invisible': [('ui_hide_commission_fields', '=', True)]}</attribute>
<attribute name="invisible">
ui_hide_commission_fields == True
</attribute>
</xpath>
</field>
</record>
Expand Down
6 changes: 3 additions & 3 deletions tg_sale_commission/wizard/wizard_settle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@


class SaleCommissionMakeSettle(models.TransientModel):
_inherit = "sale.commission.make.settle"
_inherit = "commission.make.settle"

def _get_settlement(self, agent, company, sett_from, sett_to):
def _get_settlement(self, agent, company, currency, sett_from, sett_to):
if company.commission_settlement_company:
company = company.commission_settlement_company
return super()._get_settlement(agent, company, sett_from, sett_to)
return super()._get_settlement(agent, company, currency, sett_from, sett_to)

def _prepare_settlement_vals(self, agent, company, sett_from, sett_to):
if company.commission_settlement_company:
Expand Down

0 comments on commit fceabeb

Please sign in to comment.