Skip to content

Commit

Permalink
[FIX] Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocorato committed Jan 4, 2024
1 parent ee058ef commit 0af93f3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 63 deletions.
4 changes: 1 addition & 3 deletions mis_builder_cash_flow_sale/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,4 @@ def create_cashflow_lines(cr, registry):
for sale in sales:
i += 1
sale.order_line._refresh_cashflow_line()
_logger.info(
"Creating cashflow line for sale order #%s/%s" % (i, i_max)
)
_logger.info("Creating cashflow line for sale order #%s/%s" % (i, i_max))
27 changes: 14 additions & 13 deletions mis_builder_cash_flow_sale/models/sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools import float_is_zero, float_round
from odoo.tools import config, float_is_zero, float_round


class SaleOrder(models.Model):
Expand All @@ -28,15 +28,18 @@ def write(self, vals):

@api.constrains("payment_mode_id")
def _check_payment_mode(self):
for record in self:
if (
record.payment_mode_id
and record.payment_mode_id.bank_account_link != "fixed"
):
raise ValidationError(
_("Payment mode %s used in sale orders must be of type fixed.")
% record.payment_mode_id.name
)
if not config["test_enable"] or self.env.context.get(
"test_mis_builder_cash_flow_sale"
):
for record in self:
if (
record.payment_mode_id
and record.payment_mode_id.bank_account_link != "fixed"
):
raise ValidationError(
_("Payment mode %s used in sale orders must be of type fixed.")
% record.payment_mode_id.name
)


class SaleOrderLine(models.Model):
Expand Down Expand Up @@ -138,9 +141,7 @@ def _refresh_cashflow_line(self):
0,
0,
{
"name": _(
"Due line #%s/%s of Sale order %s"
)
"name": _("Due line #%s/%s of Sale order %s")
% (i, len(totlines), line.order_id.name),
"date": dueline[0],
"sale_balance_currency": dueline[1],
Expand Down
2 changes: 1 addition & 1 deletion mis_builder_cash_flow_sale/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import test_mis_builder_cash_flow_purchase
from . import test_mis_builder_cash_flow_sale
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from odoo.tools.date_utils import relativedelta


class TestMisBuilderCashflowPurchase(SavepointCase):
class TestMisBuilderCashflowSale(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand All @@ -17,8 +17,8 @@ def setUpClass(cls):
cls.company = cls.env.ref("base.main_company")
cls.payment_mode_model = cls.env["account.payment.mode"]
cls.journal_model = cls.env["account.journal"]
cls.manual_out = cls.env.ref("account.account_payment_method_manual_out")
cls.manual_out.bank_account_required = True
cls.manual_in = cls.env.ref("account.account_payment_method_manual_in")
cls.manual_in.bank_account_required = True
cls.journal_c1 = cls.journal_model.create(
{
"name": "J1",
Expand Down Expand Up @@ -60,74 +60,86 @@ def setUpClass(cls):
"user_type_id": cls.env.ref("account.data_account_type_liquidity").id,
}
)
cls.supplier_payment_mode = cls.payment_mode_model.create(
cls.customer_payment_mode = cls.payment_mode_model.create(
{
"name": "Suppliers Bank Payment",
"name": "Customers Bank Payment",
"bank_account_link": "fixed",
"payment_method_id": cls.manual_out.id,
"payment_method_id": cls.manual_in.id,
"show_bank_account_from_journal": True,
"company_id": cls.company.id,
"fixed_journal_id": cls.journal_c1.id,
}
)

def test_01_purchase_no_payment_term_cashflow(self):
purchase_form = Form(self.env["purchase.order"])
purchase_form.partner_id = self.vendor
purchase_form.payment_mode_id = self.supplier_payment_mode
with purchase_form.order_line.new() as order_line_form:
def test_01_sale_no_payment_term_cashflow(self):
sale_form = Form(
self.env["sale.order"].with_context(test_mis_builder_cash_flow_sale=True)
)
sale_form.partner_id = self.vendor
sale_form.payment_mode_id = self.customer_payment_mode
with sale_form.order_line.new() as order_line_form:
order_line_form.product_id = self.product
order_line_form.product_qty = 5.0
order_line_form.product_uom_qty = 5.0
order_line_form.price_unit = 13.0
order_line_form.date_planned = fields.Date.today() + relativedelta(days=40)
with purchase_form.order_line.new() as order_line_form:
order_line_form.commitment_date = fields.Date.today() + relativedelta(
days=40
)
with sale_form.order_line.new() as order_line_form:
order_line_form.product_id = self.product1
order_line_form.product_qty = 5.0
order_line_form.product_uom_qty = 5.0
order_line_form.price_unit = 19.0
order_line_form.date_planned = fields.Date.today() + relativedelta(days=70)
purchase_order = purchase_form.save()
order_line_form.commitment_date = fields.Date.today() + relativedelta(
days=70
)
sale_order = sale_form.save()
self.assertEqual(
len(purchase_order.order_line), 2, msg="Order line was not created"
len(sale_order.order_line), 2, msg="Order line was not created"
)
purchase_order.button_confirm()
po_lines = purchase_order.order_line.filtered(
sale_order.action_confirm()
so_lines = sale_order.order_line.filtered(
lambda x: x.product_id == self.product
)
self.assertEqual(len(po_lines), 1)
for line in po_lines:
self.assertEqual(len(so_lines), 1)
for line in so_lines:
self.assertTrue(line.cashflow_line_ids)
self.assertAlmostEqual(
sum(line.mapped("cashflow_line_ids.purchase_balance_forecast")),
sum(line.mapped("cashflow_line_ids.sale_balance_forecast")),
-line.price_total,
)

def test_02_purchase_payment_term_2rate_cashflow(self):
purchase_form = Form(self.env["purchase.order"])
purchase_form.partner_id = self.vendor
purchase_form.payment_term_id = self.payment_term_2rate
purchase_form.payment_mode_id = self.supplier_payment_mode
with purchase_form.order_line.new() as order_line_form:
def test_02_sale_payment_term_2rate_cashflow(self):
sale_form = Form(
self.env["sale.order"].with_context(test_mis_builder_cash_flow_sale=True)
)
sale_form.partner_id = self.vendor
sale_form.payment_term_id = self.payment_term_2rate
sale_form.payment_mode_id = self.customer_payment_mode
with sale_form.order_line.new() as order_line_form:
order_line_form.product_id = self.product
order_line_form.product_qty = 5.0
order_line_form.product_uom_qty = 5.0
order_line_form.price_unit = 13.0
order_line_form.date_planned = fields.Date.today() + relativedelta(days=40)
with purchase_form.order_line.new() as order_line_form:
order_line_form.commitment_date = fields.Date.today() + relativedelta(
days=40
)
with sale_form.order_line.new() as order_line_form:
order_line_form.product_id = self.product1
order_line_form.product_qty = 5.0
order_line_form.product_uom_qty = 5.0
order_line_form.price_unit = 19.0
order_line_form.date_planned = fields.Date.today() + relativedelta(days=70)
purchase_order = purchase_form.save()
order_line_form.commitment_date = fields.Date.today() + relativedelta(
days=70
)
sale_order = sale_form.save()
self.assertEqual(
len(purchase_order.order_line), 2, msg="Order line was not created"
len(sale_order.order_line), 2, msg="Order line was not created"
)
purchase_order.button_confirm()
po_lines = purchase_order.order_line.filtered(
sale_order.action_confirm()
so_lines = sale_order.order_line.filtered(
lambda x: x.product_id == self.product
)
self.assertEqual(len(po_lines), 1)
for line in po_lines:
self.assertEqual(len(so_lines), 1)
for line in so_lines:
self.assertEqual(len(line.cashflow_line_ids), 2)
self.assertAlmostEqual(
sum(line.mapped("cashflow_line_ids.purchase_balance_forecast")),
sum(line.mapped("cashflow_line_ids.sale_balance_forecast")),
-line.price_total,
)
10 changes: 5 additions & 5 deletions mis_builder_cash_flow_sale/views/sale.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="sale_order_form" model="ir.ui.view">
<record id="view_order_form" model="ir.ui.view">
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath
expr="//field[@name='order_line']/form/group/group/notebook"
position="inside"
expr="//field[@name='order_line']/form/field[@name='company_id']"
position="after"
>
<page string="Cash flow" groups="account.group_account_manager">
<div string="Cash flow" groups="account.group_account_manager">
<field name="cashflow_line_ids">
<tree editable="bottom">
<field name="date" />
Expand All @@ -25,7 +25,7 @@
/>
</tree>
</field>
</page>
</div>
</xpath>
</field>
</record>
Expand Down

0 comments on commit 0af93f3

Please sign in to comment.