Skip to content

Commit

Permalink
[MIG]l10n_it_riba_sale_commission: Migration to v16
Browse files Browse the repository at this point in the history
  • Loading branch information
matteonext committed Oct 14, 2024
1 parent 32f48fe commit c5faa0f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 62 deletions.
4 changes: 2 additions & 2 deletions l10n_it_riba_sale_commission/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "ITA - Integrazione tra RiBa e provvigioni su vendite",
"summary": "Modulo ponte tra provvigioni agenti e RiBa",
"version": "14.0.1.1.0",
"version": "16.0.1.0.0",
"development_status": "Alpha",
"category": "Localization/Italy",
"website": "https://github.com/OCA/l10n-italy",
Expand All @@ -13,7 +13,7 @@
"installable": True,
"depends": [
"sale_commission",
"l10n_it_ricevute_bancarie",
"l10n_it_riba",
],
"data": [
"views/invoice_no_commission.xml",
Expand Down
94 changes: 41 additions & 53 deletions l10n_it_riba_sale_commission/tests/test_riba_sale_commission.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
# Copyright 2023 Nextev
# License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html

from datetime import datetime

from dateutil.relativedelta import relativedelta

from odoo import fields
from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase


class TestRibaCommission(SavepointCase):
class TestRibaCommission(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.distinta_model = cls.env["riba.distinta"]
cls.commission_model = cls.env["sale.commission"]
cls.distinta_model = cls.env["riba.slip"]
cls.commission_model = cls.env["commission"]
cls.account_model = cls.env["account.account"]
cls.move_line_model = cls.env["account.move.line"]

Expand All @@ -40,10 +39,11 @@ def setUpClass(cls):
cls.sale_account = cls.env["account.account"].search(
[
(
"user_type_id",
"account_type",
"=",
cls.env.ref("account.data_account_type_revenue").id,
)
"income_other",
),
("company_id", "=", cls.env.company.id),
],
limit=1,
)
Expand All @@ -54,72 +54,69 @@ def setUpClass(cls):
cls.expenses_account = cls.env["account.account"].search(
[
(
"user_type_id",
"account_type",
"=",
cls.env.ref("account.data_account_type_expenses").id,
)
"expense",
),
("company_id", "=", cls.env.company.id),
],
limit=1,
)
cls.bank_account = cls.env["account.account"].search(
[
(
"user_type_id",
"account_type",
"=",
cls.env.ref("account.data_account_type_liquidity").id,
)
"asset_cash",
),
("company_id", "=", cls.env.company.id),
],
limit=1,
)
cls.account_user_type = cls.env.ref("account.data_account_type_receivable")
cls.unsolved_account = cls.env["account.account"].create(
{
"code": "Past Due",
"code": "PastDue",
"name": "Past Due Bills Account (test)",
"reconcile": True,
"user_type_id": cls.account_user_type.id,
"account_type": "asset_receivable",
}
)
cls.account_rec1_id = cls.account_model.create(
dict(
code="cust_acc",
code="custacc",
name="customer account",
user_type_id=cls.account_user_type.id,
account_type="asset_receivable",
reconcile=True,
)
)
cls.account_asset_user_type = cls.env.ref(
"account.data_account_type_fixed_assets"
)
cls.sbf_effects = cls.env["account.account"].create(
{
"code": "STC",
"name": "STC Bills (test)",
"reconcile": True,
"user_type_id": cls.account_user_type.id,
"account_type": "asset_receivable",
}
)
cls.riba_account = cls.env["account.account"].create(
{
"code": "C/O",
"name": "C/O Account (test)",
"user_type_id": cls.account_asset_user_type.id,
"code": "RiBa",
"name": "RiBa Account (test)",
"account_type": "asset_fixed",
}
)
cls.company_bank = cls.env.ref("l10n_it_ricevute_bancarie.company_bank")
cls.company_bank = cls.env.ref("l10n_it_riba.company_bank")
cls.riba_config = cls.env["riba.configuration"].create(
{
"name": "Subject To Collection",
"type": "sbf",
"safety_days": 5,
"bank_id": cls.company_bank.id,
"acceptance_journal_id": cls.bank_journal.id,
"accreditation_journal_id": cls.bank_journal.id,
"credit_journal_id": cls.bank_journal.id,
"acceptance_account_id": cls.sbf_effects.id,
"accreditation_account_id": cls.riba_account.id,
"credit_account_id": cls.riba_account.id,
"bank_account_id": cls.bank_account.id,
"bank_expense_account_id": cls.expenses_account.id,
"unsolved_journal_id": cls.bank_journal.id,
"past_due_journal_id": cls.bank_journal.id,
"overdue_effects_account_id": cls.unsolved_account.id,
"protest_charge_account_id": cls.expenses_account.id,
}
Expand All @@ -130,9 +127,9 @@ def setUpClass(cls):
cls.partner.write({"agent": False})
cls.sale_order_model = cls.env["sale.order"]
cls.advance_inv_model = cls.env["sale.advance.payment.inv"]
cls.settle_model = cls.env["sale.commission.settlement"]
cls.make_settle_model = cls.env["sale.commission.make.settle"]
cls.make_inv_model = cls.env["sale.commission.make.invoice"]
cls.settle_model = cls.env["commission.settlement"]
cls.make_settle_model = cls.env["commission.make.settle"]
cls.make_inv_model = cls.env["commission.make.invoice"]
cls.product = cls.env.ref("product.product_product_5")
cls.product.list_price = 5 # for testing specific commission section
cls.commission_product = cls.env["product.product"].create(
Expand All @@ -153,13 +150,6 @@ def setUpClass(cls):
}
)

cls.income_account = cls.env["account.account"].search(
[
("company_id", "=", cls.company.id),
("user_type_id.name", "=", "Income"),
],
limit=1,
)
cls.payment_term = cls._create_riba_pterm(cls)
cls.env["res.partner.bank"].create(
{
Expand Down Expand Up @@ -217,23 +207,23 @@ def _create_riba_pterm(self):
0,
{
"value": "balance",
"option": "day_following_month",
"months": 1,
"days": 1,
},
)
],
}
)

def _settle_agent(self, agent=None, period=None, date=None, date_payment_to=None):
def _settle_agent(self, agent=None, period=None, date=None):
vals = {
"date_to": (
fields.Datetime.from_string(fields.Datetime.now())
+ relativedelta(months=period)
)
if period
else date,
"date_payment_to": date_payment_to,
"settlement_type": "sale_invoice",
}
if agent:
vals["agent_ids"] = [(4, agent.id)]
Expand All @@ -252,20 +242,18 @@ def register_payment(self, invoice):
if move_line.account_id.id == self.account_rec1_id.id:
riba_move_line_id = move_line.id
action = wizard_riba_issue.with_context(
{"active_ids": [riba_move_line_id]}
active_ids=[riba_move_line_id]
).create_list()
riba_list_id = action and action["res_id"] or False
riba_list = self.distinta_model.browse(riba_list_id)
riba_list.confirm()
riba_list._compute_acceptance_move_ids()
wiz_accreditation = (
self.env["riba.accreditation"]
self.env["riba.credit"]
.with_context(
{
"active_model": "riba.distinta",
"active_ids": [riba_list_id],
"active_id": riba_list_id,
}
active_model="riba.slip",
active_ids=[riba_list_id],
active_id=riba_list_id,
)
.create(
{
Expand All @@ -281,8 +269,8 @@ def test_riba_settlement(self):
self.register_payment(invoice)
invoice_not_settle = self._create_invoice(date - relativedelta(days=4))
self.register_payment(invoice_not_settle)
self._settle_agent(self.agent_monthly, 1, date_payment_to=datetime.now())
settlements = self.env["sale.commission.settlement"].search(
self._settle_agent(self.agent_monthly, 1)
settlements = self.env["commission.settlement"].search(
[
(
"agent_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
<record model="ir.ui.view" id="riba_safety_days">
<field name="name">riba.conf.form.safety.days</field>
<field name="model">riba.configuration</field>
<field
name="inherit_id"
ref="l10n_it_ricevute_bancarie.view_riba_configuration_form"
/>
<field name="inherit_id" ref="l10n_it_riba.view_riba_configuration_form" />
<field name="arch" type="xml">
<field name="type" position="after">
<field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


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

def _get_agent_lines(self, agent, date_to_agent):
"""
Expand All @@ -25,13 +25,13 @@ def _get_agent_lines(self, agent, date_to_agent):
# removes lines if RiBa is past due or in case it is subject to collection
# and at least the safety days have not passed since the payment due date,
# to keep a margin and verify that it has been paid.
riba_mv_lines = self.env["riba.distinta.move.line"].search(
riba_mv_lines = self.env["riba.slip.move.line"].search(
[("move_line_id.move_id", "=", line.invoice_id.id)]
)
for riba_mv_line in riba_mv_lines:
riba_type = riba_mv_line.riba_line_id.type
if line.commission_id.invoice_state == "paid" and (
line.invoice_id.is_unsolved
line.invoice_id.is_past_due
or (
(
riba_mv_line.riba_line_id.due_date
Expand Down

0 comments on commit c5faa0f

Please sign in to comment.