i want to make a price selection for odoo.
I set it as one2many on product.product. It only consists of a field price type and a price.
What i want is the following:
choosable price_types should be apple, peach or lemon
- no price selection records created:
-- domain for type_id is apple, peach or lemon
- 1 record created with type apple:
-- domain for record 1: type_id is apple, peach or lemon
-- domain for new record: type_id is peach or lemon
- second record created with typle peach:
-- domain for record 1: type_id is apple or lemon
-- domain for record 2: type_id is peach or lemon
-- domain for new record: type_id is lemon
- third record created with typle lemon:
-- domain for record 1: type_id is apple
-- domain for record 2: type_id is peach
-- domain for record 3: type_id is lemon
-- new record: no further record could be created as no type_id left
the reason i want to keep the actual selected value per record in the domain is that odoo doesn't seem to like if i remove the currently selected value from the domain
My price selection is below class "product_draft_prices". price_type is the field type_id and the combination (type_id, product_id) has to be unique.
is the above mentioned filtering possible with domain filter ? The price types are stored in the separate table product_draft_pr_types especially for domain filtering.
So i want to set a domain filter on record basis.
I think the closest existing widget for this to refer is the many2manywidget. Here you can also choose only records which are not already assigned.
product Expansion
class product_product(models.Model):
_inherit = 'product.product'
product_draft_prices = fields.One2many('product.product.draft_prices', 'product_id', string='Produktpreise', copy=True, auto_join=True)
Product price table
class product_draft_prices(models.Model):
_name = 'product.product.draft_prices'
_description = 'product.product.draft_prices'
_sql_constraints = [('unique_type', 'unique(type_id, product_id)',
'Fehler bei Produktpreisen:\n\nDieser Preistyp ist ' + \
'für dieses Produkt schon vergeben, bitte anderen auswählen')]
product_id = fields.Many2one('product.product', string='Produkt', required=True, copy=False)
type_id = fields.Many2one('product.product.draft_pr_types', required=True, string="Preistyp")
name = fields.Char('Name des Produktpreises')
price = fields.Float('Preiseingabe', required=True, digits='Product Price')
Product price types
class product_draft_pr_types(models.Model):
_name = 'product.product.draft_pr_types'
_description = 'product.product.draft_pr_types'
types = ['apple', 'peach', 'melon']
name = fields.Char('Preistyp')
Thanks in advance
You can try this.I don't know exactly it will work or not. I wish even it cannot be solved, you may get some reference.
class product_draft_prices(models.Model):
_name = 'product.product.draft_prices'
_description = 'product.product.draft_prices'
_sql_constraints = [('unique_type', 'unique(type_id, product_id)',
'Fehler bei Produktpreisen:\n\nDieser Preistyp ist ' + \
'für dieses Produkt schon vergeben, bitte anderen auswählen')]
product_id = fields.Many2one('product.product', string='Produkt', required=True, copy=False)
type_id = fields.Many2one('product.product.draft_pr_types', required=True, string="Preistyp")
name = fields.Char('Name des Produktpreises')
price = fields.Float('Preiseingabe', required=True, digits='Product Price')
@api.onchange('type_id','product_id.product_draft_prices')
def onchange_type_id(self):
price_list=[]
for plist in self.product_id.product_draft_prices:
price_list.append(plist.type_id.price_type.id)
return {'domain':{'type_id':[('price_type','not in',price_list)]}}
Change your selection field into many2one.
class product_draft_pr_types(models.Model):
_name = 'product.product.draft_pr_types'
_description = 'product.product.draft_pr_types'
types = field.many2one(product.type,string="Type")
name = fields.Char('Preistyp')
class type(models.Model):
_name = "product.type"
name= field.Char(string="Type name")