diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-06-18 11:50:20 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-06-18 11:50:20 +0700 |
| commit | 27ae2de4c1deea61dc0891379c8c294e4399b5f7 (patch) | |
| tree | a5a53cfde32ccc9ffd96ce93966c73d457e7bdab /fixco_custom/models/sale_pricelist.py | |
| parent | a79927c64928c71208a8f97ce80c5ea54b662295 (diff) | |
sale pricelist, customer type, end line bundling
Diffstat (limited to 'fixco_custom/models/sale_pricelist.py')
| -rw-r--r-- | fixco_custom/models/sale_pricelist.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/fixco_custom/models/sale_pricelist.py b/fixco_custom/models/sale_pricelist.py new file mode 100644 index 0000000..6af81fe --- /dev/null +++ b/fixco_custom/models/sale_pricelist.py @@ -0,0 +1,31 @@ +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + +class SalePricelist(models.Model): + _name = 'sale.pricelist' + _rec_name = 'product_id' + _inherit = ['mail.thread', 'mail.activity.mixin'] + + name = fields.Char(string='Name', compute="_compute_name") + product_id = fields.Many2one('product.product', string="Product", required=True) + price = fields.Float(string='Price', required=True) + + _sql_constraints = [ + ('product_unique', 'unique(product_id)', 'Product sudah ada dalam daftar harga! Pilih product lain.'), + ] + + @api.depends('product_id') + def _compute_name(self): + for record in self: + record.name = record.product_id.display_name + + @api.constrains('product_id') + def _check_product_duplicate(self): + for record in self: + existing = self.search([ + ('product_id', '=', record.product_id.id), + ('id', '!=', record.id) + ], limit=1) + if existing: + raise ValidationError(_('Product %s sudah ada dalam daftar harga (ID: %s).') % + (record.product_id.display_name, existing.id))
\ No newline at end of file |
