[IMP] account_asset_number: Add barcode type configuration

This commit is contained in:
Pani-k-folk
2024-09-20 11:58:56 +07:00
parent 488740c4b0
commit 061a30b458
3 changed files with 72 additions and 28 deletions

View File

@@ -17,7 +17,28 @@ class AccountAssetProfile(models.Model):
string="Asset Number Sequence", string="Asset Number Sequence",
domain=lambda self: self._get_domain_sequence_id(), domain=lambda self: self._get_domain_sequence_id(),
) )
barcode_type = fields.Selection(
selection=[("barcode", "Barcode"), ("qr", "QR")],
default="barcode",
)
barcode_width = fields.Integer(
default=350,
help="Width (in px) of the barcode or the QR code",
)
barcode_height = fields.Integer(
default=75,
help="Height (in px) of the barcode or the QR code",
)
@api.model @api.model
def _get_domain_sequence_id(self): def _get_domain_sequence_id(self):
return [("company_id", "in", [False, self.env.company.id])] return [("company_id", "in", [False, self.env.company.id])]
@api.onchange("barcode_type")
def _onchange_barcode_type(self):
# Set default values when type is changed
if self.barcode_type == "barcode":
self.barcode_width = 300
self.barcode_height = 75
elif self.barcode_type == "qr":
self.barcode_width = 150

View File

@@ -10,26 +10,36 @@
</tr> </tr>
<tr> <tr>
<td class="text-center align-middle" style="height: 6rem;"> <td class="text-center align-middle" style="height: 6rem;">
<t t-set="profile" t-value="asset.profile_id" />
<t t-if="asset.number"> <t t-if="asset.number">
<img <t t-if="profile.barcode_type == 'barcode'">
alt="Barcode" <img
t-if="len(asset.number) == 13" alt="Barcode"
t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', quote_plus(asset.number or ''), 600, 150)" t-if="len(asset.number) == 13"
style="width:100%;height:4rem;" t-att-src="'/report/barcode/?barcode_type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN13', quote_plus(asset.number or ''), profile.barcode_width, profile.barcode_height)"
/> style="display: block; margin: 0 auto;"
<img />
alt="Barcode" <img
t-elif="len(asset.number) == 8" alt="Barcode"
t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN8', quote_plus(asset.number or ''), 600, 150)" t-elif="len(asset.number) == 8"
style="width:100%;height:4rem;" t-att-src="'/report/barcode/?barcode_type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('EAN8', quote_plus(asset.number or ''), profile.barcode_width, profile.barcode_height)"
/> style="display: block; margin: 0 auto;"
<img />
alt="Barcode" <img
t-else="" alt="Barcode"
t-att-src="'/report/barcode/?type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', quote_plus(asset.number or ''), 600, 150)" t-else=""
style="width:100%;height:4rem" t-att-src="'/report/barcode/?barcode_type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', quote_plus(asset.number or ''), profile.barcode_width, profile.barcode_height)"
/> style="display: block; margin: 0 auto;"
<span t-field="asset.number" /> />
</t>
<t t-elif="profile.barcode_type == 'qr'">
<img
alt="QRcode"
t-att-src="'/report/barcode/?barcode_type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('QR', quote_plus(asset.number or ''), profile.barcode_width, profile.barcode_width)"
style="display: block; margin: 0 auto;"
/>
</t>
<span t-field="asset.number" />
</t> </t>
<t t-else=""> <t t-else="">
<span class="text-muted">No number available</span> <span class="text-muted">No number available</span>

View File

@@ -8,15 +8,28 @@
ref="account_asset_management.account_asset_profile_view_form" ref="account_asset_management.account_asset_profile_view_form"
/> />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath <xpath expr="//sheet/group/group[last()]" position="after">
expr="//sheet/group/group/field[@name='company_id']" <group string="QR/Barcode Configuration">
position="after" <field
> name="barcode_type"
<field name="use_sequence" /> attrs="{'required': [('use_sequence', '=', True)]}"
<field />
name="sequence_id" <field
attrs="{'invisible':[('use_sequence', '!=', True)], 'required':[('use_sequence', '=', True)]}" name="barcode_width"
/> attrs="{'required': [('use_sequence', '=', True)]}"
/>
<field
name="barcode_height"
attrs="{'invisible': [('barcode_type', '=', 'qr')],
'required': [('use_sequence', '=', True)]}"
/>
<field name="use_sequence" />
<field
name="sequence_id"
attrs="{'invisible': [('use_sequence', '!=', True)],
'required': [('use_sequence', '=', True)]}"
/>
</group>
</xpath> </xpath>
</field> </field>
</record> </record>