mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-26 22:12:03 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -2,6 +2,7 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.sale_mrp.tests import test_sale_mrp_flow
|
||||
from odoo.fields import Command
|
||||
from odoo.tests import common, Form
|
||||
|
||||
|
||||
|
|
@ -50,3 +51,87 @@ class TestSaleMrpFlow(test_sale_mrp_flow.TestSaleMrpFlowCommon):
|
|||
self.assertEqual(so.order_line.purchase_price, 60)
|
||||
so.action_confirm()
|
||||
self.assertEqual(so.order_line.purchase_price, 60)
|
||||
|
||||
def test_kit_cost_calculation_2(self):
|
||||
""" Check that the average cost price is computed correctly after receipt validation:
|
||||
Lovely KIT BOM for 10:
|
||||
- 1O unit of Kit $50
|
||||
- 10 units of “component b” $10
|
||||
-> $60 per Lovely Kit
|
||||
SUB KIT BOM:
|
||||
- 1 units of “component a” 1 x $30 = $30
|
||||
- 2 units of “component b” 2 x $10 = $20
|
||||
-> $50 per SUB Kit
|
||||
"""
|
||||
sub_kit, kit = self._cls_create_product('Sub Kit', self.uom_unit), self._cls_create_product('Lovely Kit', self.uom_ten)
|
||||
kit.uom_ids = [Command.set([self.uom_unit.id, self.uom_ten.id])]
|
||||
self.product_category.property_cost_method = 'average'
|
||||
self.product_category.property_valuation = 'real_time'
|
||||
(kit + sub_kit + self.component_a + self.component_b).categ_id = self.product_category
|
||||
self.env['mrp.bom'].create([
|
||||
{
|
||||
'product_tmpl_id': sub_kit.product_tmpl_id.id,
|
||||
'product_qty': 1.0,
|
||||
'type': 'phantom',
|
||||
'bom_line_ids': [
|
||||
Command.create({
|
||||
'product_id': self.component_a.id,
|
||||
'product_qty': 1.0,
|
||||
}),
|
||||
Command.create({
|
||||
'product_id': self.component_b.id,
|
||||
'product_qty': 2.0,
|
||||
}),
|
||||
],
|
||||
},
|
||||
{
|
||||
'product_tmpl_id': kit.product_tmpl_id.id,
|
||||
'product_uom_id': kit.uom_id.id,
|
||||
'product_qty': 1.0,
|
||||
'type': 'phantom',
|
||||
'bom_line_ids': [
|
||||
Command.create({
|
||||
'product_id': sub_kit.id,
|
||||
'product_qty': 10.0,
|
||||
}),
|
||||
Command.create({
|
||||
'product_id': self.component_b.id,
|
||||
'product_qty': 10.0,
|
||||
}),
|
||||
],
|
||||
},
|
||||
])
|
||||
self.component_a.standard_price = 30
|
||||
self.component_b.standard_price = 10
|
||||
sub_kit.action_bom_cost()
|
||||
kit.action_bom_cost()
|
||||
so = self.env['sale.order'].create({
|
||||
'partner_id': self.partner_a.id,
|
||||
'order_line': [Command.create({
|
||||
'product_id': kit.id,
|
||||
'product_uom_qty': 3,
|
||||
'product_uom_id': self.uom_ten.id
|
||||
})]
|
||||
})
|
||||
self.assertEqual(so.order_line.purchase_price, 600)
|
||||
so.action_confirm()
|
||||
self.assertEqual(so.order_line.purchase_price, 600)
|
||||
for move in so.picking_ids.move_ids:
|
||||
move.quantity = move.product_uom_qty
|
||||
self.assertRecordValues(so.order_line, [{'purchase_price': 600, 'qty_delivered': 0.0}])
|
||||
so.picking_ids.button_validate()
|
||||
self.assertEqual(so.picking_ids.state, 'done')
|
||||
self.assertRecordValues(so.order_line, [{'purchase_price': 600, 'qty_delivered': 3.0}])
|
||||
self.assertEqual(so.order_line.purchase_price, 600)
|
||||
# create an invoice to check that the cost price on the invoice line is correct
|
||||
inv_1 = so._create_invoices()
|
||||
inv_1.action_post()
|
||||
self.assertEqual(inv_1.state, 'posted', 'invoice should be in posted state')
|
||||
# The cost price on the invoice line should be 600 * 3 = 1800
|
||||
self.assertRecordValues(inv_1.line_ids, [
|
||||
{'debit': 0.0, 'credit': 3.0},
|
||||
{'debit': 0.0, 'credit': 0.45},
|
||||
{'debit': 3.45, 'credit': 0.0},
|
||||
{'debit': 0.0, 'credit': 1800},
|
||||
{'debit': 1800, 'credit': 0.0},
|
||||
])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue