| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
from odoo import _, api, models, fields |
| 4 |
from odoo.exceptions import ValidationError |
| 5 |
|
| 6 |
|
| 7 |
class ProductCombo(models.Model): |
| 8 |
_name = 'product.combo' |
| 9 |
_inherit = ['product.combo', 'pos.load.mixin'] |
| 10 |
|
| 11 |
qty_max = fields.Integer(string="Maximum quantity", default=1, help="Maximum number of items to select in the combo.") |
| 12 |
qty_free = fields.Integer(string="Free quantity", default=1, help="Number of free items included in the combo.") |
| 13 |
|
| 14 |
@api.model |
| 15 |
def _load_pos_data_domain(self, data, config): |
| 16 |
return [('id', 'in', list(set().union(*[product.get('combo_ids') for product in data['product.template']])))] |
| 17 |
|
| 18 |
@api.model |
| 19 |
def _load_pos_data_fields(self, config): |
| 20 |
return ['id', 'name', 'combo_item_ids', 'base_price', 'qty_free', 'qty_max'] |
| 21 |
|
| 22 |
@api.constrains('qty_max') |
| 23 |
def _check_qty_max(self): |
| 24 |
if any(combo.qty_max < 1 for combo in self): |
| 25 |
raise ValidationError(_("The maximum quantity of a combo must be greater or equal to 1.")) |
| 26 |
|
| 27 |
@api.constrains('qty_free') |
| 28 |
def _check_qty_free(self): |
| 29 |
if any(combo.qty_free < 0 for combo in self): |
| 30 |
raise ValidationError(_("The free quantity of a combo must be greater or equal to 0.")) |
| 31 |
|
| 32 |
@api.constrains('qty_max', 'qty_free') |
| 33 |
def _check_qty_max_greater_than_qty_free(self): |
| 34 |
if any(combo.qty_free > combo.qty_max for combo in self): |
| 35 |
raise ValidationError(_("The free quantity must be smaller or equal to the maximum quantity.")) |