Initial commit
This commit is contained in:
1
garazd_product_label_print/wizard/__init__.py
Normal file
1
garazd_product_label_print/wizard/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import print_product_label
|
||||
41
garazd_product_label_print/wizard/print_product_label.py
Normal file
41
garazd_product_label_print/wizard/print_product_label.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright © 2023 Garazd Creation (<https://garazd.biz>)
|
||||
# @author: Yurii Razumovskyi (<support@garazd.biz>)
|
||||
# @author: Iryna Razumovska (<support@garazd.biz>)
|
||||
# License OPL-1 (https://www.odoo.com/documentation/15.0/legal/licenses.html).
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from odoo import api, models
|
||||
from odoo.tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
|
||||
LABEL_ATTACHMENT_NAME = 'Product Label Direct Printing'
|
||||
|
||||
|
||||
class PrintProductLabel(models.TransientModel):
|
||||
_inherit = "print.product.label"
|
||||
|
||||
def action_print_direct(self):
|
||||
""" Print labels directly without download. """
|
||||
self.ensure_one()
|
||||
attachment = self.env['ir.attachment'].create({
|
||||
'name': LABEL_ATTACHMENT_NAME,
|
||||
'type': 'binary',
|
||||
'datas': self.get_pdf(),
|
||||
'mimetype': 'application/pdf',
|
||||
'public': False,
|
||||
})
|
||||
return {
|
||||
'type': 'ir.actions.act_url',
|
||||
'url': f'/print_label/{attachment.id}',
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
@api.autovacuum
|
||||
def _gc_print_label_attachments(self):
|
||||
timeout_ago = datetime.utcnow() - timedelta(days=1)
|
||||
domain = [
|
||||
('name', '=', LABEL_ATTACHMENT_NAME),
|
||||
('mimetype', '=', 'application/pdf'),
|
||||
('create_date', '<', timeout_ago.strftime(DEFAULT_SERVER_DATETIME_FORMAT)),
|
||||
]
|
||||
return self.env['ir.attachment'].sudo().search(domain).unlink()
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="print_product_label_view_form" model="ir.ui.view">
|
||||
<field name="name">print.product.label.view.form.inherit.garazd_product_label_print</field>
|
||||
<field name="model">print.product.label</field>
|
||||
<field name="inherit_id" ref="garazd_product_label.print_product_label_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//button[@name='action_print']" position="before">
|
||||
<button name="action_print_direct"
|
||||
string="Print"
|
||||
help="Print product labels"
|
||||
type="object"
|
||||
icon="fa-print"
|
||||
class="btn-primary mr8"/>
|
||||
</xpath>
|
||||
<xpath expr="//button[@name='action_print']" position="attributes">
|
||||
<attribute name="string">Download</attribute>
|
||||
<attribute name="help">Download product labels</attribute>
|
||||
<attribute name="icon">fa-download</attribute>
|
||||
<attribute name="class" separator=" " remove="btn-primary" add="btn-light border"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user