mirror of
https://github.com/bringout/oca-workflow-process.git
synced 2026-04-21 06:12:07 +02:00
Initial commit: OCA Workflow Process packages (456 packages)
This commit is contained in:
commit
d366e42934
18799 changed files with 1284507 additions and 0 deletions
|
|
@ -0,0 +1,4 @@
|
|||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
from . import test_product_supplierinfo_discount
|
||||
from . import test_purchase_discount
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
# Copyright 2018 GRAP - Sylvain Legal
|
||||
# Copyright 2019 Tecnativa - Pedro M. Baeza
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields
|
||||
from odoo.tests.common import Form, TransactionCase
|
||||
|
||||
from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
|
||||
|
||||
|
||||
class TestProductSupplierinfoDiscount(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
|
||||
cls.supplierinfo_model = cls.env["product.supplierinfo"]
|
||||
cls.purchase_order_line_model = cls.env["purchase.order.line"]
|
||||
cls.partner_1 = cls.env.ref("base.res_partner_1")
|
||||
cls.partner_3 = cls.env.ref("base.res_partner_3")
|
||||
cls.product = cls.env.ref("product.product_product_6")
|
||||
cls.supplierinfo = cls.supplierinfo_model.create(
|
||||
{
|
||||
"min_qty": 0.0,
|
||||
"partner_id": cls.partner_3.id,
|
||||
"product_tmpl_id": cls.product.product_tmpl_id.id,
|
||||
"discount": 10,
|
||||
}
|
||||
)
|
||||
cls.supplierinfo2 = cls.supplierinfo_model.create(
|
||||
{
|
||||
"min_qty": 10.0,
|
||||
"partner_id": cls.partner_3.id,
|
||||
"product_tmpl_id": cls.product.product_tmpl_id.id,
|
||||
"discount": 20,
|
||||
}
|
||||
)
|
||||
cls.purchase_order = cls.env["purchase.order"].create(
|
||||
{"partner_id": cls.partner_3.id}
|
||||
)
|
||||
cls.po_line_1 = cls.purchase_order_line_model.create(
|
||||
{
|
||||
"order_id": cls.purchase_order.id,
|
||||
"product_id": cls.product.id,
|
||||
"date_planned": fields.Datetime.now(),
|
||||
"name": "Test",
|
||||
"product_qty": 1.0,
|
||||
"product_uom": cls.env.ref("uom.product_uom_categ_unit").id,
|
||||
"price_unit": 10.0,
|
||||
}
|
||||
)
|
||||
|
||||
def test_001_purchase_order_partner_3_qty_1(self):
|
||||
purchase_form = Form(self.purchase_order)
|
||||
with purchase_form.order_line.edit(0) as line:
|
||||
line.product_qty = 1.0
|
||||
self.assertEqual(
|
||||
line.discount,
|
||||
10,
|
||||
"Incorrect discount for product 6 with partner 3 and qty 1: "
|
||||
"Should be 10%",
|
||||
)
|
||||
|
||||
def test_002_purchase_order_partner_3_qty_10(self):
|
||||
purchase_form = Form(self.purchase_order)
|
||||
with purchase_form.order_line.edit(0) as line:
|
||||
line.product_qty = 10.0
|
||||
self.assertEqual(
|
||||
line.discount,
|
||||
20.0,
|
||||
"Incorrect discount for product 6 with partner 3 and qty 10: "
|
||||
"Should be 20%",
|
||||
)
|
||||
|
||||
def test_003_purchase_order_partner_1_qty_1(self):
|
||||
purchase_form = Form(self.purchase_order)
|
||||
purchase_form.partner_id = self.partner_1
|
||||
with purchase_form.order_line.edit(0) as line:
|
||||
line.product_qty = 1
|
||||
self.assertEqual(
|
||||
line.discount,
|
||||
0.0,
|
||||
"Incorrect discount for product 6 with partner 1 and qty 1",
|
||||
)
|
||||
|
||||
def test_004_prepare_purchase_order_line(self):
|
||||
res = self.purchase_order_line_model._prepare_purchase_order_line(
|
||||
self.product,
|
||||
50,
|
||||
self.env.ref("uom.product_uom_unit"),
|
||||
self.env.ref("base.main_company"),
|
||||
self.supplierinfo,
|
||||
self.purchase_order,
|
||||
)
|
||||
self.assertTrue(res.get("discount"), "Should have a discount key")
|
||||
|
||||
def test_005_default_supplierinfo_discount(self):
|
||||
# Create an original supplierinfo
|
||||
supplierinfo = self.supplierinfo_model.create(
|
||||
{
|
||||
"min_qty": 0.0,
|
||||
"partner_id": self.partner_3.id,
|
||||
"product_tmpl_id": self.product.product_tmpl_id.id,
|
||||
"discount": 10,
|
||||
}
|
||||
)
|
||||
# Change the partner and raise onchange function
|
||||
self.partner_1.default_supplierinfo_discount = 15
|
||||
with Form(supplierinfo) as supplierinfo_form:
|
||||
supplierinfo_form.partner_id = self.partner_1
|
||||
self.assertEqual(
|
||||
supplierinfo_form.discount,
|
||||
15,
|
||||
"Incorrect discount for supplierinfo "
|
||||
" after changing partner that has default discount defined.",
|
||||
)
|
||||
|
||||
def test_006_supplierinfo_from_purchaseorder(self):
|
||||
"""Include discount when creating new sellers for a product"""
|
||||
partner = self.env.ref("base.res_partner_3")
|
||||
product = self.env.ref("product.product_product_8")
|
||||
self.assertFalse(
|
||||
self.supplierinfo_model.search(
|
||||
[
|
||||
("partner_id", "=", partner.id),
|
||||
("product_tmpl_id", "=", product.product_tmpl_id.id),
|
||||
]
|
||||
)
|
||||
)
|
||||
order = self.env["purchase.order"].create({"partner_id": partner.id})
|
||||
self.purchase_order_line_model.create(
|
||||
{
|
||||
"date_planned": fields.Datetime.now(),
|
||||
"discount": 40,
|
||||
"name": product.name,
|
||||
"price_unit": 10.0,
|
||||
"product_id": product.id,
|
||||
"product_qty": 1.0,
|
||||
"product_uom": product.uom_po_id.id,
|
||||
"order_id": order.id,
|
||||
}
|
||||
)
|
||||
order.button_confirm()
|
||||
seller = self.supplierinfo_model.search(
|
||||
[
|
||||
("partner_id", "=", partner.id),
|
||||
("product_tmpl_id", "=", product.product_tmpl_id.id),
|
||||
]
|
||||
)
|
||||
self.assertTrue(seller)
|
||||
self.assertEqual(seller.discount, 40)
|
||||
|
||||
def test_007_change_price_unit_autoupdate_stock_move(self):
|
||||
partner = self.env.ref("base.res_partner_3")
|
||||
product = self.env.ref("product.product_product_8")
|
||||
order = self.env["purchase.order"].create({"partner_id": partner.id})
|
||||
self.purchase_order_line_model.create(
|
||||
{
|
||||
"date_planned": fields.Datetime.now(),
|
||||
"discount": 40,
|
||||
"name": product.name,
|
||||
"price_unit": 10.0,
|
||||
"product_id": product.id,
|
||||
"product_qty": 1.0,
|
||||
"product_uom": product.uom_po_id.id,
|
||||
"order_id": order.id,
|
||||
}
|
||||
)
|
||||
order.button_confirm()
|
||||
self.assertEqual(order.order_line.move_ids.price_unit, 6)
|
||||
order.order_line.price_unit = 100
|
||||
self.assertEqual(order.order_line.move_ids.price_unit, 60)
|
||||
|
|
@ -0,0 +1,210 @@
|
|||
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# Copyright 2015-2019 Tecnativa - Pedro M. Baeza
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields
|
||||
from odoo.tests.common import Form, TransactionCase
|
||||
|
||||
from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
|
||||
|
||||
|
||||
class TestPurchaseOrder(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestPurchaseOrder, cls).setUpClass()
|
||||
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
|
||||
cls.categ_cost_average = cls.env["product.category"].create(
|
||||
{"name": "Average cost method category", "property_cost_method": "average"}
|
||||
)
|
||||
product_obj = cls.env["product.product"]
|
||||
cls.product_1 = product_obj.create(
|
||||
{"name": "Test product 1", "categ_id": cls.categ_cost_average.id}
|
||||
)
|
||||
cls.product_2 = product_obj.create({"name": "Test product 2"})
|
||||
po_model = cls.env["purchase.order.line"]
|
||||
currency_rate_model = cls.env["res.currency.rate"]
|
||||
# Set the Exchange rate for the currency of the company to 1
|
||||
# to avoid issues with rates
|
||||
latest_currency_rate_line = currency_rate_model.search(
|
||||
[
|
||||
("currency_id", "=", cls.env.user.company_id.currency_id.id),
|
||||
("name", "=", fields.Date.today()),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if latest_currency_rate_line and latest_currency_rate_line.rate != 1.0:
|
||||
latest_currency_rate_line.rate = 1.0
|
||||
elif not latest_currency_rate_line:
|
||||
currency_rate_model.create(
|
||||
{
|
||||
"currency_id": cls.env.user.company_id.currency_id.id,
|
||||
"rate": 1.00,
|
||||
"name": fields.Date.today(),
|
||||
}
|
||||
)
|
||||
cls.purchase_order = cls.env["purchase.order"].create(
|
||||
{"partner_id": cls.env.ref("base.res_partner_3").id}
|
||||
)
|
||||
cls.po_line_1 = po_model.create(
|
||||
{
|
||||
"order_id": cls.purchase_order.id,
|
||||
"product_id": cls.product_1.id,
|
||||
"date_planned": fields.Datetime.now(),
|
||||
"name": "Test",
|
||||
"product_qty": 1.0,
|
||||
"product_uom": cls.product_1.uom_id.id,
|
||||
"discount": 50.0,
|
||||
"price_unit": 10.0,
|
||||
"taxes_id": [],
|
||||
}
|
||||
)
|
||||
cls.account = cls.env["account.account"].create(
|
||||
{
|
||||
"name": "Test account",
|
||||
"code": "TEST",
|
||||
"account_type": "expense",
|
||||
}
|
||||
)
|
||||
cls.tax = cls.env["account.tax"].create(
|
||||
{
|
||||
"name": "Sample tax 15%",
|
||||
"amount_type": "percent",
|
||||
"type_tax_use": "purchase",
|
||||
"amount": 15.0,
|
||||
"invoice_repartition_line_ids": [
|
||||
(0, 0, {"factor_percent": 100, "repartition_type": "base"}),
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"factor_percent": 100,
|
||||
"repartition_type": "tax",
|
||||
"account_id": cls.account.id,
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
||||
)
|
||||
cls.po_line_2 = po_model.create(
|
||||
{
|
||||
"order_id": cls.purchase_order.id,
|
||||
"product_id": cls.product_2.id,
|
||||
"date_planned": fields.Datetime.now(),
|
||||
"name": "Test",
|
||||
"product_qty": 10.0,
|
||||
"product_uom": cls.product_2.uom_id.id,
|
||||
"discount": 30,
|
||||
"taxes_id": [(6, 0, [cls.tax.id])],
|
||||
"price_unit": 230.0,
|
||||
}
|
||||
)
|
||||
cls.po_line_3 = po_model.create(
|
||||
{
|
||||
"order_id": cls.purchase_order.id,
|
||||
"product_id": cls.product_2.id,
|
||||
"date_planned": fields.Datetime.now(),
|
||||
"name": "Test",
|
||||
"product_qty": 1.0,
|
||||
"product_uom": cls.product_2.uom_id.id,
|
||||
"discount": 0,
|
||||
"taxes_id": [(6, 0, [cls.tax.id])],
|
||||
"price_unit": 10.0,
|
||||
}
|
||||
)
|
||||
cls.po_line_4 = po_model.create(
|
||||
{
|
||||
"order_id": cls.purchase_order.id,
|
||||
"display_type": "line_section",
|
||||
"name": "Test Section",
|
||||
"product_qty": 0.0,
|
||||
"product_uom_qty": 0.0,
|
||||
}
|
||||
)
|
||||
|
||||
def test_purchase_order_vals(self):
|
||||
self.assertEqual(self.po_line_1.price_subtotal, 5.0)
|
||||
self.assertEqual(self.po_line_2.price_subtotal, 1610.0)
|
||||
self.assertEqual(self.po_line_3.price_subtotal, 10.0)
|
||||
self.assertEqual(self.purchase_order.amount_untaxed, 1625.0)
|
||||
self.assertEqual(self.purchase_order.amount_tax, 243)
|
||||
# Change price to launch a recalculation of totals
|
||||
self.po_line_1.discount = 60
|
||||
self.assertEqual(self.po_line_1.price_subtotal, 4.0)
|
||||
self.assertEqual(self.purchase_order.amount_untaxed, 1624.0)
|
||||
self.assertEqual(self.purchase_order.amount_tax, 243)
|
||||
|
||||
def test_move_price_unit(self):
|
||||
self.purchase_order.button_confirm()
|
||||
picking = self.purchase_order.picking_ids
|
||||
moves = picking.move_ids
|
||||
move1 = moves.filtered(lambda x: x.purchase_line_id == self.po_line_1)
|
||||
self.assertEqual(move1.price_unit, 5)
|
||||
move2 = moves.filtered(lambda x: x.purchase_line_id == self.po_line_2)
|
||||
self.assertEqual(move2.price_unit, 161)
|
||||
move3 = moves.filtered(lambda x: x.purchase_line_id == self.po_line_3)
|
||||
self.assertEqual(move3.price_unit, 10)
|
||||
# Confirm the picking to see the cost price
|
||||
move1.move_line_ids.qty_done = 1
|
||||
picking._action_done()
|
||||
self.assertAlmostEqual(self.product_1.standard_price, 5.0)
|
||||
# Check data in PO remains the same - This is due to the hack
|
||||
self.assertAlmostEqual(self.po_line_1.price_unit, 10.0)
|
||||
self.assertAlmostEqual(self.po_line_1.discount, 50.0)
|
||||
|
||||
def test_move_price_unit_discount_sync(self):
|
||||
self.purchase_order.button_confirm()
|
||||
picking = self.purchase_order.picking_ids
|
||||
moves = picking.move_ids
|
||||
self.po_line_1.discount = 25
|
||||
self.po_line_2.discount = 50
|
||||
self.po_line_3.discount = 10
|
||||
move1 = moves.filtered(lambda x: x.purchase_line_id == self.po_line_1)
|
||||
self.assertEqual(move1.price_unit, 7.5)
|
||||
move2 = moves.filtered(lambda x: x.purchase_line_id == self.po_line_2)
|
||||
self.assertEqual(move2.price_unit, 115.0)
|
||||
move3 = moves.filtered(lambda x: x.purchase_line_id == self.po_line_3)
|
||||
self.assertEqual(move3.price_unit, 9.0)
|
||||
self.po_line_1.price_unit = 1000
|
||||
self.po_line_2.price_unit = 500
|
||||
self.po_line_3.price_unit = 250
|
||||
move1 = moves.filtered(lambda x: x.purchase_line_id == self.po_line_1)
|
||||
self.assertEqual(move1.price_unit, 750.0)
|
||||
move2 = moves.filtered(lambda x: x.purchase_line_id == self.po_line_2)
|
||||
self.assertEqual(move2.price_unit, 250.0)
|
||||
move3 = moves.filtered(lambda x: x.purchase_line_id == self.po_line_3)
|
||||
self.assertEqual(move3.price_unit, 225.0)
|
||||
|
||||
def test_report_price_unit(self):
|
||||
rec = self.env["purchase.report"].search(
|
||||
[("product_id", "=", self.product_1.id)]
|
||||
)
|
||||
self.assertEqual(rec.price_total, 5)
|
||||
self.assertEqual(rec.discount, 50)
|
||||
|
||||
def test_no_product(self):
|
||||
purchase_form = Form(self.purchase_order)
|
||||
with purchase_form.order_line.edit(3) as line:
|
||||
line.product_qty = 0.0
|
||||
self.assertEqual(self.po_line_4.discount, 0.0)
|
||||
|
||||
def test_invoice(self):
|
||||
invoice = self.env["account.move"].new(
|
||||
{
|
||||
"move_type": "out_invoice",
|
||||
"partner_id": self.env.ref("base.res_partner_3").id,
|
||||
"purchase_id": self.purchase_order.id,
|
||||
}
|
||||
)
|
||||
invoice._onchange_purchase_auto_complete()
|
||||
line = invoice.invoice_line_ids.filtered(
|
||||
lambda x: x.purchase_line_id == self.po_line_1
|
||||
)
|
||||
self.assertAlmostEqual(line.discount, 50)
|
||||
line = invoice.invoice_line_ids.filtered(
|
||||
lambda x: x.purchase_line_id == self.po_line_2
|
||||
)
|
||||
self.assertAlmostEqual(line.discount, 30)
|
||||
line = invoice.invoice_line_ids.filtered(
|
||||
lambda x: x.purchase_line_id == self.po_line_3
|
||||
)
|
||||
self.assertAlmostEqual(line.discount, 0)
|
||||
Loading…
Add table
Add a link
Reference in a new issue