diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-01-23 10:03:15 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-01-23 10:03:15 +0700 |
| commit | 2a47fdafcb12440c68e346d35d465b0a0c800945 (patch) | |
| tree | 4cf4b28477b46ab7080f7e1d222d515b6a1999ff /indoteknik_custom/models/barcoding_product.py | |
| parent | 11a561355208a403d635b16d6c306cc9f19eb714 (diff) | |
push
Diffstat (limited to 'indoteknik_custom/models/barcoding_product.py')
| -rw-r--r-- | indoteknik_custom/models/barcoding_product.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/indoteknik_custom/models/barcoding_product.py b/indoteknik_custom/models/barcoding_product.py new file mode 100644 index 00000000..41444646 --- /dev/null +++ b/indoteknik_custom/models/barcoding_product.py @@ -0,0 +1,36 @@ +from odoo import models, api, fields +from odoo.exceptions import AccessError, UserError, ValidationError +from datetime import timedelta, date, datetime +import logging + +_logger = logging.getLogger(__name__) + +class BarcodingProduct(models.Model): + _name = "barcoding.product" + _description = "Barcoding Product" + + barcoding_product_line = fields.One2many('barcoding.product.line', 'barcoding_product_id', string='Barcoding Product Lines', auto_join=True) + product_id = fields.Many2one('product.product', string="Product", tracking=3) + quantity = fields.Float(string="Quantity", tracking=3) + + @api.onchange('product_id', 'quantity') + def _onchange_product_or_quantity(self): + """Update barcoding_product_line based on product_id and quantity""" + if self.product_id and self.quantity > 0: + # Clear existing lines + self.barcoding_product_line = [(5, 0, 0)] + + # Add a new line with the current product and quantity + self.barcoding_product_line = [(0, 0, { + 'product_id': self.product_id.id, + 'barcoding_product_id': self.id, + }) for _ in range(int(self.quantity))] + + +class BarcodingProductLine(models.Model): + _name = 'barcoding.product.line' + _description = 'Barcoding Product Line' + _order = 'barcoding_product_id, id' + + barcoding_product_id = fields.Many2one('barcoding.product', string='Barcoding Product Ref', required=True, ondelete='cascade', index=True, copy=False) + product_id = fields.Many2one('product.product', string="Product")
\ No newline at end of file |
