mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
Add possibility to automatically create procurement group
This commit is contained in:
@@ -11,7 +11,35 @@ class MrpProduction(models.Model):
|
||||
raw_material_procurement_group_id = fields.Many2one(
|
||||
string="Raw Material Procurement Group",
|
||||
comodel_name="procurement.group",
|
||||
readonly=True,
|
||||
states={
|
||||
"draft": [("readonly", False)],
|
||||
},
|
||||
)
|
||||
auto_create_procurement_group = fields.Boolean(
|
||||
string="Auto Create Procurement Group",
|
||||
readonly=True,
|
||||
states={
|
||||
"draft": [("readonly", False)],
|
||||
},
|
||||
)
|
||||
|
||||
@api.multi
|
||||
def action_confirm(self):
|
||||
for mo in self:
|
||||
mo._create_procurement_group()
|
||||
return super(MrpProduction, self).action_confirm()
|
||||
|
||||
@api.multi
|
||||
def _create_procurement_group(self):
|
||||
self.ensure_one()
|
||||
obj_group = self.env[
|
||||
"procurement.group"]
|
||||
if self.auto_create_procurement_group and \
|
||||
not self.raw_material_procurement_group_id:
|
||||
obj_group.create({
|
||||
"name": self.name,
|
||||
})
|
||||
|
||||
@api.model
|
||||
def _make_consume_line_from_data(
|
||||
|
||||
@@ -64,7 +64,8 @@ class MrpProductionCase(TransactionCase):
|
||||
src_loc=False,
|
||||
dest_loc=False,
|
||||
group=False,
|
||||
qty=10.0):
|
||||
qty=10.0,
|
||||
auto=False):
|
||||
if not product:
|
||||
product = self.product1
|
||||
uom = product.uom_id
|
||||
@@ -82,10 +83,11 @@ class MrpProductionCase(TransactionCase):
|
||||
"raw_material_procurement_group_id": group,
|
||||
"product_qty": qty,
|
||||
"product_uom": uom.id,
|
||||
"auto_create_procurement_group": auto,
|
||||
}
|
||||
return self.obj_mo.create(res)
|
||||
|
||||
def test_1(self):
|
||||
def test_no_create_group(self):
|
||||
# Create MO
|
||||
mo = self._create_mo()
|
||||
# Click confirm button
|
||||
@@ -104,7 +106,7 @@ class MrpProductionCase(TransactionCase):
|
||||
len(raw.group_id),
|
||||
0)
|
||||
|
||||
def test_2(self):
|
||||
def test_create_group_manual(self):
|
||||
group1 = self._create_procurement_group(
|
||||
"X 001")
|
||||
# Create MO
|
||||
@@ -125,3 +127,23 @@ class MrpProductionCase(TransactionCase):
|
||||
self.assertEqual(
|
||||
raw.group_id,
|
||||
group1)
|
||||
|
||||
def test_create_group_auto(self):
|
||||
mo = self._create_mo(
|
||||
group=False,
|
||||
auto=True)
|
||||
# Click confirm button
|
||||
mo.signal_workflow("button_confirm")
|
||||
for raw in mo.move_lines:
|
||||
self.assertEqual(
|
||||
raw.location_id,
|
||||
self.loc_stock_2)
|
||||
self.assertEqual(
|
||||
raw.location_dest_id,
|
||||
self.loc_production)
|
||||
self.assertEqual(
|
||||
raw.procure_method,
|
||||
"make_to_order")
|
||||
self.assertEqual(
|
||||
raw.group_id,
|
||||
mo.raw_material_procurement_group_id)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="//field[@name='location_src_id']" position="after">
|
||||
<field name="auto_create_procurement_group"/>
|
||||
<field name="raw_material_procurement_group_id"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
||||
Reference in New Issue
Block a user