0
votes

I'm working on Odoo 10 and developing a module to add new functionalities to the stock module, but I'm facing two problems when I'm on a good merchandise entry (with the list of products to transfert into wharehouse):

- First, I would like to extend the View0 (stock_picking_views.xml, record: view_picking_form) by adding a new computed field in the "Operations" tree view. But when I try to add this field Odoo tells me it doesn't exist:

File "/usr/local/lib/python2.7/dist-packages/odoo-10.0.post20170508-py2.7.egg/odoo/models.py", line 1083, in _validate_fields raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e))) ParseError: "Error while validating constraint

Field computed_field does not exist

class MyClass(models.Model):
    _inherit = ['stock.picking']

    computed_field = fields.Float(string='my field', default=0.0, compute='_computefield')

    @api.depends('pack_operation_ids.fieldA', 'pack_operation_ids.fieldB')
    def _computefield(self):
        self.computed_field = self.pack_operation_ids.fieldA - self.pack_operation_ids.fieldB

I don't understand because I'm able to add the computed_field in another page of the View0, where it appears well and is computed each time other values changes. So any idea on what I'm doing wrong ? I'm new to Odoo and there is probably a lot of things I'm missing for now.

- Second issue, I've created a button which open a new window above this View0. And I would like to get some fields shown on the View0. But I don't know how to do it because these View0 fields are not clearly defined in View0 model (stock.picking). They are all put into a Many2one field from stock.pack.operation and accessed with functions in the stock.picking model.

My second model also inherit from stock.picking:

class MyModel2(models.Model):
    _name = 'stock.picking.model2'
    _inherit = ['stock.picking']

A help on these to issues would be really helpful, and if I need to precise something don't hesitates to tell me.

Thanks

2

2 Answers

0
votes

Part 1 of your question:

It sounds like you are trying to add a new field into the Operations tree view.

The problem with your attempt is that you added your computed_field onto the stock.picking module. Once you are adding fields within the pack_operation_product_ids (Operations tree view), the model is stock.pack.operation. If the computed_field is not also available to that model, then Odoo will give the error you have received.


Part 2 of your question:

I would need to see more details about what exactly you are trying to do.

  • Why are you creating an entirely new model, stock.picking.model2?
  • What fields are you trying to display on the wizard (popup form view)?
0
votes

Thanks a lot for your answer travisw,

For part 1, I understand know, it was logical but I didn't see it. I suppose I just have to add the field into the stock.pack.operation table so, thanks :)

For part 2, I want a wizard with a new design. And if I'm not wrong (tell me if so), if I don't create a new model I have to inherit from the active view and modify from that, and it's not what I want.

The only thing I need from the active view to create the wizard, is the products related to the goods entry (product_id, qty_done, product_qty).

I made some additional researches, and found that it could be done by retrieving the active view id with the context and then find a way to retrieve good fields thanks to that ? Is it possible in this case and do you know how ?