This question has been flagged
2633 Views

Hi,

I am trying to create a Manufacturing Calculation view to calculate the quantities of necessary materials (and equivalent materials in case of lacking the main materials) to produce a product.

Note: This view is only for calculating and doesn't make any stock move.

My solution is to make a copy of Manufacturing Order view. And here is my choices
Solution 1:

Create a new view which inherited from Manufacturing Order view. 

Then use the same model 'mrp.production' as the parent view for calculating. 

However, if I add my logic for calculating in my new view, it changes the logic of the parent view also 

=> It's not my choice

Solution 2:

Create a new view with new model named 'mrp.production.cal', which is prototype inheritance model of 'mrp.production' model. Then I can add my calculation logic to the new model.

However, when I try to create and click 'Save' button. And I don't really know the reason. 

The error shows as below

×The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set

[object with reference: Production Order - mrp.production]


Here is my source code for solution 2:

class MrpProductionCalculation(models.Model):
_inherit = 'mrp.production'
_name = 'mrp.production.cal'

Am I doing the right way?

Thanks for any help!

UPDATE:
The details error is
odoo.sql_db: bad query: b'INSERT INTO "stock_move" ("id", "create_uid", "create_date", "write_uid", "write_date", "additional", "company_id", "date", "date_expected", "group_id", "is_done", "location_dest_id", "location_id", "name", "origin", "picking_type_id", "priority", "procure_method", "product_id", "product_uom", "product_uom_qty", "production_id", "propagate", "scrapped", "sequence", "state", "to_refund", "warehouse_id") VALUES (nextval(\'stock_move_id_seq\'), 2, (now() at time zone \'UTC\'), 2, (now() at time zone \'UTC\'), false, 1, \'2019-06-12 04:04:58\', \'2019-06-12 04:04:58\', 23, false, 12, 7, \'WH/MO/00023\', \'WH/MO/00023\', 18, \'1\', \'make_to_stock\', 28, 1, \'10.000\', 13, false, false, 10, \'draft\', false, 1) RETURNING id'
ERROR: insert or update on table "stock_move" violates foreign key constraint "stock_move_production_id_fkey"
DETAIL: Key (production_id)=(13) is not present in table "mrp_production".

Avatar
Discard