0

I try to override many2one field with many2many

 property_product_pricelist = fields.Many2many('product.pricelist',
                                                      string="Sale Pricelist",
                                                      help="This pricelist will be used, instead of the default one, for sales to the current partner")

and i get this error when try to save values

File "/home//workspace/odoo-9.0/openerp/models.py", line 5384, in _browse
    env.prefetch[cls._name].update(ids)
TypeError: unhashable type: 'list'

also i tryid like this

property_product_pricelist = fields.Many2many('product.pricelist', column1='partner_id', column2='pricelist_id') 

but get

ProgrammingError: column product_pricelist_res_partner_rel.pricelist_id does not exist

LINE 1: SELECT product_pricelist_res_partner_rel.pricelist_id, produ...

Chaban33
  • 1,362
  • 11
  • 38
  • 1
    I would suggest you not to do that because if a Many2one field already exists, it must be used at many different places and you will have errors everywhere, because a singleton is expected instead of a list. You should create another field instead. – Harlan Aug 07 '18 at 06:01
  • What you are doing is bad because you will break the logic.Ask you the question `why I need a many2many field ?` – Kenly Aug 07 '18 at 13:17

1 Answers1

0

Best solution I came up with.

  • create a many2many field totally new
  • write an onchange method which sets the value of the original field (here the many2one) to the new many2many field
multiply_pricelists_ids = fields.Many2many(
        'product.pricelist', string='Multiply Pricelists')

    @api.onchange('property_product_pricelist')
    @api.multi
    def pricelist_change(self):
        self.multiply_pricelists_ids =  self.property_product_pricelist
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
Chaban33
  • 1,362
  • 11
  • 38