コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
1493 ビュー

How can I adjust/a a product print label size? the sticker that I am currently using is 4x2 in which it is not available.


Is there a way for me to adjust or add new print label size?

アバター
破棄
最善の回答

Hi,
For some layouts for example DYMO, the paper format is available,so you can try changing it from the db and see if it works for you



Thanks

アバター
破棄
最善の回答

Hi,


You may need to inherit the product.label.layout model and create a new format to print in a new label size. The following code will guide you in achieving this,


Firstly Inherit the model,

class ProductLabelLayout(models.TransientModel):

_inherit = 'product.label.layout'


print_format = fields.Selection(selection_add=[('new_format', 'Format'),], ondelete={'new_format': 'set default'})


def _prepare_report_data(self):

xml_id, data = super()._prepare_report_data()

if 'new_format' in self.print_format:

xml_id = 'report.custom_labels.report_new_format'

data = {

'active_model': active_model,

'product_tmpl_name': self.product_tmpl_ids.name,

'product_tmpl_price': price,

#you can add the data needed to print in the label

}

return xml_id, data


Controller for Report,

class ReportProductLabelTag(models.AbstractModel):

_name = 'report.custom_labels.report_new_format'

_description = 'Label'


def _get_report_values(self, docids, data):

if data.get('active_model') == 'product.template':

Product = self.env['product.template']

elif data.get('active_model') == 'product.product':

Product = self.env['product.product']

else:

raise UserError( _('Product model not defined, Please contact your administrator.'))

return {

'doc_ids': docids,

'data': data,

}


Paperfromat for label layout,
<record id="paperformat_layout_label" model="report.paperformat">
<field name="name">Label</field>
<field name="default" eval="True"/>
<field name="format">custom</field>
<field name="page_height">267</field>
<field name="page_width">175</field>
<field name="orientation">Landscape</field>
<field name="margin_top">0</field>
<field name="margin_bottom">0</field>
<field name="margin_left">0</field>
<field name="margin_right">0</field>
<field name="disable_shrinking" eval="True"/>
<field name="header_line" eval="False"/>
<field name="header_spacing">0</field>
<field name="dpi">96</field>
</record>

Action for report,
<record id="report_new_format" model="ir.actions.report">
<field name="name">New</field>
<field name="model">product.template</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">module_name.report_new_format</field>
<field name="report_file">module_name.report_new_format</field>
<field name="paperformat_id"ref="paperformat_layout_label"/>
</record>

Create custom template layout,
<template id="report_new_format">
<!-- Add template format -->

<template>


Hope it helps

アバター
破棄