1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
from odoo import fields, models, api, tools, _
from datetime import datetime, timedelta, date
from odoo.exceptions import UserError
import logging
import requests
import json
import re
import qrcode, base64
from bs4 import BeautifulSoup
from io import BytesIO
class ProductProduct(models.Model):
_inherit = "product.product"
bundling_line_ids = fields.One2many('bundling.line', 'product_id', string="Bundling Lines", auto_join=True)
qty_pcs_box = fields.Float("Pcs Box")
barcode_box = fields.Char("Barcode Box")
qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant')
qty_multiple = fields.Float('Minimum Beli')
brand_id = fields.Many2one('brands', string='Brand', required=True)
product_public_category_id = fields.Many2one('product.public.category', string='Public Categories')
categ_id = fields.Many2one('product.category', string='Category', required=False)
# brand_id = fields.Many2one(required=True)
default_code = fields.Char(required=True)
taxed_id = fields.Many2many('taxes', string='Taxes', required=True)
def action_open_pricelist_wizard(self):
return {
'name': 'Create Purchase Pricelist',
'type': 'ir.actions.act_window',
'res_model': 'purchase.pricelist.wizard',
'view_mode': 'form',
'target': 'new',
'context': {
'default_product_id': self.id,
}
}
def check_multiple_qty(self, other_qty):
if self.qty_multiple > 0 and other_qty > 0:
multiple = self.qty_multiple
if other_qty % multiple != 0:
return True
else:
return False
@api.constrains('name', 'default_code')
def constrains_product_type(self):
self.type = 'product'
def _compute_qr_code_variant(self):
for rec in self:
# Skip inactive variants
if not rec.active:
rec.qr_code_variant = False # Clear the QR Code for archived variants
continue
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=5,
border=4,
)
qr.add_data(rec.barcode if rec.barcode else rec.default_code)
qr.make(fit=True)
img = qr.make_image(fill_color="black", back_color="white")
buffer = BytesIO()
img.save(buffer, format="PNG")
qr_code_img = base64.b64encode(buffer.getvalue()).decode()
rec.qr_code_variant = qr_code_img
class BundlingLine(models.Model):
_name = "bundling.line"
product_id = fields.Many2one('product.product', string="Product")
variant_id = fields.Many2one('product.product', string="Variant")
master_sku = fields.Char(string="Master SKU")
price = fields.Float(string="Price")
product_uom_qty = fields.Float(string="Quantity")
|