mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] account_move_line_manufacture_info: black, isort
This commit is contained in:
@@ -3,20 +3,16 @@
|
||||
{
|
||||
"name": "Account Move Line Manufacture Information",
|
||||
"version": "12.0.1.0.0",
|
||||
"depends": [
|
||||
"stock_account",
|
||||
"mrp"
|
||||
],
|
||||
"author": "Eficent,"
|
||||
"Odoo Community Association (OCA)",
|
||||
"depends": ["stock_account", "mrp"],
|
||||
"author": "Eficent," "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/manufacture",
|
||||
"category": "Manufacture Management",
|
||||
"installable": True,
|
||||
"license": "AGPL-3",
|
||||
"data": [
|
||||
'security/ir.model.access.csv',
|
||||
'views/account_move_line_view.xml',
|
||||
'views/mrp_production_views.xml',
|
||||
'views/mrp_unbuild_views.xml',
|
||||
]
|
||||
"security/ir.model.access.csv",
|
||||
"views/account_move_line_view.xml",
|
||||
"views/mrp_production_views.xml",
|
||||
"views/mrp_unbuild_views.xml",
|
||||
],
|
||||
}
|
||||
|
||||
@@ -5,12 +5,15 @@ from odoo import fields, models
|
||||
|
||||
|
||||
class AccountMoveLine(models.Model):
|
||||
_inherit = 'account.move.line'
|
||||
_inherit = "account.move.line"
|
||||
|
||||
manufacture_order_id = fields.Many2one(
|
||||
comodel_name='mrp.production', string='Manufacture Order', copy=False,
|
||||
index=True)
|
||||
comodel_name="mrp.production",
|
||||
string="Manufacture Order",
|
||||
copy=False,
|
||||
index=True,
|
||||
)
|
||||
|
||||
unbuild_order_id = fields.Many2one(
|
||||
comodel_name='mrp.unbuild', string='Unbuild Order', copy=False,
|
||||
index=True)
|
||||
comodel_name="mrp.unbuild", string="Unbuild Order", copy=False, index=True
|
||||
)
|
||||
|
||||
@@ -5,21 +5,22 @@ from odoo import api, models
|
||||
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = 'stock.move'
|
||||
_inherit = "stock.move"
|
||||
|
||||
@api.model
|
||||
def _prepare_account_move_line(self, qty, cost,
|
||||
credit_account_id, debit_account_id):
|
||||
def _prepare_account_move_line(
|
||||
self, qty, cost, credit_account_id, debit_account_id
|
||||
):
|
||||
res = super(StockMove, self)._prepare_account_move_line(
|
||||
qty, cost, credit_account_id, debit_account_id)
|
||||
qty, cost, credit_account_id, debit_account_id
|
||||
)
|
||||
for line in res:
|
||||
if self.production_id:
|
||||
line[2]['manufacture_order_id'] = self.production_id.id
|
||||
line[2]["manufacture_order_id"] = self.production_id.id
|
||||
elif self.raw_material_production_id:
|
||||
line[2]['manufacture_order_id'] = \
|
||||
self.raw_material_production_id.id
|
||||
line[2]["manufacture_order_id"] = self.raw_material_production_id.id
|
||||
elif self.unbuild_id:
|
||||
line[2]['unbuild_order_id'] = self.unbuild_id.id
|
||||
line[2]["unbuild_order_id"] = self.unbuild_id.id
|
||||
elif self.consume_unbuild_id:
|
||||
line[2]['unbuild_order_id'] = self.consume_unbuild_id.id
|
||||
line[2]["unbuild_order_id"] = self.consume_unbuild_id.id
|
||||
return res
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
* In the manufacture order the user will be able to access the account
|
||||
move lines that are related to the MO.
|
||||
* In the unbuild order the user will be able to access the account
|
||||
move lines that are related to the UO.
|
||||
move lines that are related to the UO.
|
||||
|
||||
@@ -6,105 +6,124 @@ from odoo.tests import Form
|
||||
|
||||
|
||||
class TestAccountMoveLineManufactureInfo(common.SavepointCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestAccountMoveLineManufactureInfo, cls).setUpClass()
|
||||
|
||||
cls.product_obj = cls.env['product.product']
|
||||
cls.account_move_line_obj = cls.env['account.move.line']
|
||||
cls.bom_obj = cls.env['mrp.bom']
|
||||
cls.bom_line_obj = cls.env['mrp.bom.line']
|
||||
cls.location_production = cls.env.ref('stock.location_production')
|
||||
cls.production_obj = cls.env['mrp.production']
|
||||
cls.produce_wiz = cls.env['mrp.product.produce']
|
||||
cls.unbuild_obj = cls.env['mrp.unbuild']
|
||||
cls.product_obj = cls.env["product.product"]
|
||||
cls.account_move_line_obj = cls.env["account.move.line"]
|
||||
cls.bom_obj = cls.env["mrp.bom"]
|
||||
cls.bom_line_obj = cls.env["mrp.bom.line"]
|
||||
cls.location_production = cls.env.ref("stock.location_production")
|
||||
cls.production_obj = cls.env["mrp.production"]
|
||||
cls.produce_wiz = cls.env["mrp.product.produce"]
|
||||
cls.unbuild_obj = cls.env["mrp.unbuild"]
|
||||
|
||||
# Create accounts for WIP
|
||||
cls.account_wip = cls.env['account.account'].create({
|
||||
'name': 'WIP',
|
||||
'code': '999',
|
||||
'user_type_id': cls.env.ref(
|
||||
'account.data_account_type_current_assets').id
|
||||
})
|
||||
cls.account_wip = cls.env["account.account"].create(
|
||||
{
|
||||
"name": "WIP",
|
||||
"code": "999",
|
||||
"user_type_id": cls.env.ref(
|
||||
"account.data_account_type_current_assets"
|
||||
).id,
|
||||
}
|
||||
)
|
||||
|
||||
# Create categories
|
||||
cls.categ_physical = cls.env.ref('product.product_category_5')
|
||||
cls.categ_physical.write({
|
||||
'property_valuation': 'real_time',
|
||||
})
|
||||
cls.categ_physical = cls.env.ref("product.product_category_5")
|
||||
cls.categ_physical.write({"property_valuation": "real_time"})
|
||||
|
||||
# Assign WIP account to stock location production
|
||||
cls.location_production.write({
|
||||
'valuation_in_account_id': cls.account_wip.id,
|
||||
'valuation_out_account_id': cls.account_wip.id,
|
||||
})
|
||||
cls.location_production.write(
|
||||
{
|
||||
"valuation_in_account_id": cls.account_wip.id,
|
||||
"valuation_out_account_id": cls.account_wip.id,
|
||||
}
|
||||
)
|
||||
|
||||
# Create products:
|
||||
cls.product_top = cls.product_obj.create({
|
||||
'name': 'Final Product',
|
||||
'type': 'product',
|
||||
'categ_id': cls.categ_physical.id,
|
||||
})
|
||||
cls.product_sub_1 = cls.product_obj.create({
|
||||
'name': 'L01-01',
|
||||
'type': 'product',
|
||||
'standard_price': 100.0,
|
||||
'categ_id': cls.categ_physical.id,
|
||||
})
|
||||
cls.component_1 = cls.product_obj.create({
|
||||
'name': 'RM 01',
|
||||
'type': 'product',
|
||||
'standard_price': 10.0,
|
||||
'categ_id': cls.categ_physical.id,
|
||||
})
|
||||
cls.component_2 = cls.product_obj.create({
|
||||
'name': 'RM 02',
|
||||
'type': 'product',
|
||||
'standard_price': 15.0,
|
||||
'categ_id': cls.categ_physical.id,
|
||||
})
|
||||
cls.component_3 = cls.product_obj.create({
|
||||
'name': 'RM 03',
|
||||
'type': 'product',
|
||||
'standard_price': 20.0,
|
||||
'categ_id': cls.categ_physical.id,
|
||||
})
|
||||
cls.product_top = cls.product_obj.create(
|
||||
{
|
||||
"name": "Final Product",
|
||||
"type": "product",
|
||||
"categ_id": cls.categ_physical.id,
|
||||
}
|
||||
)
|
||||
cls.product_sub_1 = cls.product_obj.create(
|
||||
{
|
||||
"name": "L01-01",
|
||||
"type": "product",
|
||||
"standard_price": 100.0,
|
||||
"categ_id": cls.categ_physical.id,
|
||||
}
|
||||
)
|
||||
cls.component_1 = cls.product_obj.create(
|
||||
{
|
||||
"name": "RM 01",
|
||||
"type": "product",
|
||||
"standard_price": 10.0,
|
||||
"categ_id": cls.categ_physical.id,
|
||||
}
|
||||
)
|
||||
cls.component_2 = cls.product_obj.create(
|
||||
{
|
||||
"name": "RM 02",
|
||||
"type": "product",
|
||||
"standard_price": 15.0,
|
||||
"categ_id": cls.categ_physical.id,
|
||||
}
|
||||
)
|
||||
cls.component_3 = cls.product_obj.create(
|
||||
{
|
||||
"name": "RM 03",
|
||||
"type": "product",
|
||||
"standard_price": 20.0,
|
||||
"categ_id": cls.categ_physical.id,
|
||||
}
|
||||
)
|
||||
|
||||
# Create Bills of Materials:
|
||||
cls.bom_top = cls.bom_obj.create({
|
||||
'product_tmpl_id': cls.product_top.product_tmpl_id.id,
|
||||
})
|
||||
cls.line_top_1 = cls.bom_line_obj.create({
|
||||
'product_id': cls.product_sub_1.id,
|
||||
'bom_id': cls.bom_top.id,
|
||||
'product_qty': 2.0,
|
||||
})
|
||||
cls.line_top_2 = cls.bom_line_obj.create({
|
||||
'product_id': cls.component_3.id,
|
||||
'bom_id': cls.bom_top.id,
|
||||
'product_qty': 3.0,
|
||||
})
|
||||
cls.bom_top = cls.bom_obj.create(
|
||||
{"product_tmpl_id": cls.product_top.product_tmpl_id.id}
|
||||
)
|
||||
cls.line_top_1 = cls.bom_line_obj.create(
|
||||
{
|
||||
"product_id": cls.product_sub_1.id,
|
||||
"bom_id": cls.bom_top.id,
|
||||
"product_qty": 2.0,
|
||||
}
|
||||
)
|
||||
cls.line_top_2 = cls.bom_line_obj.create(
|
||||
{
|
||||
"product_id": cls.component_3.id,
|
||||
"bom_id": cls.bom_top.id,
|
||||
"product_qty": 3.0,
|
||||
}
|
||||
)
|
||||
|
||||
cls.bom_sub_1 = cls.bom_obj.create({
|
||||
'product_tmpl_id': cls.product_sub_1.product_tmpl_id.id,
|
||||
})
|
||||
cls.line_sub_1_1 = cls.bom_line_obj.create({
|
||||
'product_id': cls.component_1.id,
|
||||
'bom_id': cls.bom_sub_1.id,
|
||||
'product_qty': 4.0,
|
||||
})
|
||||
cls.line_sub_1_2 = cls.bom_line_obj.create({
|
||||
'product_id': cls.component_2.id,
|
||||
'bom_id': cls.bom_sub_1.id,
|
||||
'product_qty': 1.0,
|
||||
})
|
||||
cls.bom_sub_1 = cls.bom_obj.create(
|
||||
{"product_tmpl_id": cls.product_sub_1.product_tmpl_id.id}
|
||||
)
|
||||
cls.line_sub_1_1 = cls.bom_line_obj.create(
|
||||
{
|
||||
"product_id": cls.component_1.id,
|
||||
"bom_id": cls.bom_sub_1.id,
|
||||
"product_qty": 4.0,
|
||||
}
|
||||
)
|
||||
cls.line_sub_1_2 = cls.bom_line_obj.create(
|
||||
{
|
||||
"product_id": cls.component_2.id,
|
||||
"bom_id": cls.bom_sub_1.id,
|
||||
"product_qty": 1.0,
|
||||
}
|
||||
)
|
||||
|
||||
def _produce(self, mo, qty=0.0):
|
||||
wiz = Form(self.produce_wiz.with_context({
|
||||
'active_id': mo.id,
|
||||
'active_ids': [mo.id],
|
||||
}))
|
||||
wiz = Form(
|
||||
self.produce_wiz.with_context({"active_id": mo.id, "active_ids": [mo.id]})
|
||||
)
|
||||
wiz.product_qty = qty or mo.product_qty
|
||||
produce_wizard = wiz.save()
|
||||
produce_wizard.do_produce()
|
||||
@@ -112,46 +131,49 @@ class TestAccountMoveLineManufactureInfo(common.SavepointCase):
|
||||
|
||||
def test_01_manufacture_order(self):
|
||||
"""Create Manufacture Order and check account move lines created"""
|
||||
self.product_top.write({
|
||||
'standard_price': 445.0,
|
||||
})
|
||||
mo = self.production_obj.create({
|
||||
'name': 'MO-01',
|
||||
'product_id': self.product_top.id,
|
||||
'product_uom_id': self.product_top.uom_id.id,
|
||||
'product_qty': 5.0,
|
||||
'bom_id': self.bom_top.id,
|
||||
})
|
||||
self.product_top.write({"standard_price": 445.0})
|
||||
mo = self.production_obj.create(
|
||||
{
|
||||
"name": "MO-01",
|
||||
"product_id": self.product_top.id,
|
||||
"product_uom_id": self.product_top.uom_id.id,
|
||||
"product_qty": 5.0,
|
||||
"bom_id": self.bom_top.id,
|
||||
}
|
||||
)
|
||||
mo.action_assign()
|
||||
self._produce(mo, 5.0)
|
||||
mo.button_mark_done()
|
||||
account_move_lines = self.account_move_line_obj.search([
|
||||
('manufacture_order_id', '=', mo.id)])
|
||||
account_move_lines = self.account_move_line_obj.search(
|
||||
[("manufacture_order_id", "=", mo.id)]
|
||||
)
|
||||
self.assertEqual(len(account_move_lines), 6)
|
||||
|
||||
def test_02_ubuild_order(self):
|
||||
"""Create Unbuild Order and check account move lines created"""
|
||||
self.product_top.write({
|
||||
'standard_price': 445.0,
|
||||
})
|
||||
mo = self.production_obj.create({
|
||||
'name': 'MO-01',
|
||||
'product_id': self.product_top.id,
|
||||
'product_uom_id': self.product_top.uom_id.id,
|
||||
'product_qty': 5.0,
|
||||
'bom_id': self.bom_top.id,
|
||||
})
|
||||
self.product_top.write({"standard_price": 445.0})
|
||||
mo = self.production_obj.create(
|
||||
{
|
||||
"name": "MO-01",
|
||||
"product_id": self.product_top.id,
|
||||
"product_uom_id": self.product_top.uom_id.id,
|
||||
"product_qty": 5.0,
|
||||
"bom_id": self.bom_top.id,
|
||||
}
|
||||
)
|
||||
mo.action_assign()
|
||||
self._produce(mo, 3.0)
|
||||
mo.button_mark_done()
|
||||
uo = self.unbuild_obj.create({
|
||||
'product_id': self.product_top.id,
|
||||
'bom_id': self.bom_top.id,
|
||||
'product_qty': 1.0,
|
||||
'product_uom_id': self.product_top.uom_id.id,
|
||||
})
|
||||
uo = self.unbuild_obj.create(
|
||||
{
|
||||
"product_id": self.product_top.id,
|
||||
"bom_id": self.bom_top.id,
|
||||
"product_qty": 1.0,
|
||||
"product_uom_id": self.product_top.uom_id.id,
|
||||
}
|
||||
)
|
||||
uo.action_unbuild()
|
||||
account_move_lines = self.account_move_line_obj.search([
|
||||
('unbuild_order_id', '=', uo.id)
|
||||
])
|
||||
account_move_lines = self.account_move_line_obj.search(
|
||||
[("unbuild_order_id", "=", uo.id)]
|
||||
)
|
||||
self.assertEqual(len(account_move_lines), 6)
|
||||
|
||||
Reference in New Issue
Block a user