| 1 |
|
| 2 |
|
| 3 |
from unittest import skip |
| 4 |
|
| 5 |
from odoo.addons.stock_landed_costs.tests.test_stockvaluationlayer import TestStockValuationLCCommon |
| 6 |
from odoo.tests import tagged, Form |
| 7 |
|
| 8 |
|
| 9 |
@tagged('post_install', '-at_install') |
| 10 |
@skip('Temporary to fast merge new valuation') |
| 11 |
class TestStockLandedCostsBranches(TestStockValuationLCCommon): |
| 12 |
|
| 13 |
@classmethod |
| 14 |
def setUpClass(cls): |
| 15 |
super().setUpClass() |
| 16 |
|
| 17 |
cls.branch = cls.env['res.company'].create({ |
| 18 |
'name': 'Branch', |
| 19 |
'parent_id': cls.company.id, |
| 20 |
}) |
| 21 |
cls.env['account.chart.template'].try_loading(cls.company.chart_template, company=cls.branch, install_demo=False) |
| 22 |
cls.env.user.company_id = cls.branch |
| 23 |
|
| 24 |
cls.vendor1 = cls.env['res.partner'].create({'name': 'vendor1'}) |
| 25 |
|
| 26 |
cls.product1.categ_id.property_cost_method = 'fifo' |
| 27 |
|
| 28 |
def test_create_lc_from_branch(self): |
| 29 |
""" |
| 30 |
From a company's branch, create a LC and ensure it impacts the SVL |
| 31 |
""" |
| 32 |
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.branch.id)], limit=1) |
| 33 |
supplier_location = self.env.ref('stock.stock_location_suppliers') |
| 34 |
|
| 35 |
receipt = self.env['stock.picking'].create({ |
| 36 |
'location_id': supplier_location.id, |
| 37 |
'location_dest_id': warehouse.lot_stock_id.id, |
| 38 |
'picking_type_id': warehouse.in_type_id.id, |
| 39 |
'move_ids': [(0, 0, { |
| 40 |
'location_id': supplier_location.id, |
| 41 |
'location_dest_id': warehouse.lot_stock_id.id, |
| 42 |
'picking_type_id': warehouse.in_type_id.id, |
| 43 |
'product_id': self.product1.id, |
| 44 |
'product_uom_qty': 1, |
| 45 |
'product_uom': self.product1.uom_id.id, |
| 46 |
'price_unit': 10, |
| 47 |
})], |
| 48 |
}) |
| 49 |
receipt.action_confirm() |
| 50 |
receipt.action_assign() |
| 51 |
receipt.move_line_ids.quantity = 1 |
| 52 |
receipt.button_validate() |
| 53 |
|
| 54 |
lc_form = Form(self.env['stock.landed.cost']) |
| 55 |
lc_form.picking_ids.add(receipt) |
| 56 |
with lc_form.cost_lines.new() as cost_line: |
| 57 |
cost_line.product_id = self.productlc1 |
| 58 |
cost_line.price_unit = 5 |
| 59 |
lc = lc_form.save() |
| 60 |
lc.compute_landed_cost() |
| 61 |
lc.button_validate() |
| 62 |
|
| 63 |
self.assertEqual(lc.company_id, self.branch) |
| 64 |
self.assertEqual(self.product1.value_svl, 15) |
| 65 |
self.assertEqual(self.product1.quantity_svl, 1) |
| 66 |
self.assertEqual(self.product1.standard_price, 15) |
| 67 |
|
| 68 |
def test_lc_generated_from_bill(self): |
| 69 |
""" |
| 70 |
Confirm PO, receive products, post bill and generate LC |
| 71 |
""" |
| 72 |
po_form = Form(self.env['purchase.order']) |
| 73 |
po_form.partner_id = self.vendor1 |
| 74 |
with po_form.order_line.new() as po_line: |
| 75 |
po_line.product_id = self.product1 |
| 76 |
po_line.product_qty = 1 |
| 77 |
po_line.price_unit = 10 |
| 78 |
po_line.tax_ids.clear() |
| 79 |
po = po_form.save() |
| 80 |
po.button_confirm() |
| 81 |
|
| 82 |
receipt = po.picking_ids |
| 83 |
receipt.move_line_ids.quantity = 1 |
| 84 |
receipt.button_validate() |
| 85 |
|
| 86 |
bill_form = Form.from_action(self.env, po.action_create_invoice()) |
| 87 |
bill_form.invoice_date = bill_form.date |
| 88 |
with bill_form.invoice_line_ids.new() as inv_line: |
| 89 |
inv_line.product_id = self.productlc1 |
| 90 |
inv_line.price_unit = 5 |
| 91 |
bill = bill_form.save() |
| 92 |
bill.action_post() |
| 93 |
|
| 94 |
lc_form = Form.from_action(self.env, bill.button_create_landed_costs()) |
| 95 |
lc_form.picking_ids.add(receipt) |
| 96 |
lc = lc_form.save() |
| 97 |
lc.button_validate() |
| 98 |
|
| 99 |
self.assertEqual(lc.company_id, self.branch) |
| 100 |
self.assertEqual(self.product1.value_svl, 15) |
| 101 |
self.assertEqual(self.product1.quantity_svl, 1) |
| 102 |
self.assertEqual(self.product1.standard_price, 15) |