mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-26 19:32:01 +02:00
Initial commit: Sale packages
This commit is contained in:
commit
14e3d26998
6469 changed files with 2479670 additions and 0 deletions
3
odoo-bringout-oca-ocb-product/product/wizard/__init__.py
Normal file
3
odoo-bringout-oca-ocb-product/product/wizard/__init__.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import product_label_layout
|
||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,74 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class ProductLabelLayout(models.TransientModel):
|
||||
_name = 'product.label.layout'
|
||||
_description = 'Choose the sheet layout to print the labels'
|
||||
|
||||
print_format = fields.Selection([
|
||||
('dymo', 'Dymo'),
|
||||
('2x7xprice', '2 x 7 with price'),
|
||||
('4x7xprice', '4 x 7 with price'),
|
||||
('4x12', '4 x 12'),
|
||||
('4x12xprice', '4 x 12 with price')], string="Format", default='2x7xprice', required=True)
|
||||
custom_quantity = fields.Integer('Quantity', default=1, required=True)
|
||||
product_ids = fields.Many2many('product.product')
|
||||
product_tmpl_ids = fields.Many2many('product.template')
|
||||
extra_html = fields.Html('Extra Content', default='')
|
||||
rows = fields.Integer(compute='_compute_dimensions')
|
||||
columns = fields.Integer(compute='_compute_dimensions')
|
||||
|
||||
@api.depends('print_format')
|
||||
def _compute_dimensions(self):
|
||||
for wizard in self:
|
||||
if 'x' in wizard.print_format:
|
||||
columns, rows = wizard.print_format.split('x')[:2]
|
||||
wizard.columns = int(columns)
|
||||
wizard.rows = int(rows)
|
||||
else:
|
||||
wizard.columns, wizard.rows = 1, 1
|
||||
|
||||
def _prepare_report_data(self):
|
||||
if self.custom_quantity <= 0:
|
||||
raise UserError(_('You need to set a positive quantity.'))
|
||||
|
||||
# Get layout grid
|
||||
if self.print_format == 'dymo':
|
||||
xml_id = 'product.report_product_template_label_dymo'
|
||||
elif 'x' in self.print_format:
|
||||
xml_id = 'product.report_product_template_label'
|
||||
else:
|
||||
xml_id = ''
|
||||
|
||||
active_model = ''
|
||||
if self.product_tmpl_ids:
|
||||
products = self.product_tmpl_ids.ids
|
||||
active_model = 'product.template'
|
||||
elif self.product_ids:
|
||||
products = self.product_ids.ids
|
||||
active_model = 'product.product'
|
||||
else:
|
||||
raise UserError(_("No product to print, if the product is archived please unarchive it before printing its label."))
|
||||
|
||||
# Build data to pass to the report
|
||||
data = {
|
||||
'active_model': active_model,
|
||||
'quantity_by_product': {p: self.custom_quantity for p in products},
|
||||
'layout_wizard': self.id,
|
||||
'price_included': 'xprice' in self.print_format,
|
||||
}
|
||||
return xml_id, data
|
||||
|
||||
def process(self):
|
||||
self.ensure_one()
|
||||
xml_id, data = self._prepare_report_data()
|
||||
if not xml_id:
|
||||
raise UserError(_('Unable to find report template for %s format', self.print_format))
|
||||
report_action = self.env.ref(xml_id).report_action(None, data=data)
|
||||
report_action.update({'close_on_report_download': True})
|
||||
return report_action
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<record id="product_label_layout_form" model="ir.ui.view">
|
||||
<field name="name">product.label.layout.form</field>
|
||||
<field name="model">product.label.layout</field>
|
||||
<field name="mode">primary</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group>
|
||||
<group>
|
||||
<field name="product_ids" invisible="1"/>
|
||||
<field name="product_tmpl_ids" invisible="1"/>
|
||||
<field name="custom_quantity"/>
|
||||
<field name="print_format" widget="radio"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="extra_html" widget="html" attrs="{'invisible': [('print_format', '!=', '2x7xprice')]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="process" string="Confirm" type="object" class="btn-primary"/>
|
||||
<button string="Discard" class="btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_open_label_layout" model="ir.actions.act_window">
|
||||
<field name="name">Choose Labels Layout</field>
|
||||
<field name="res_model">product.label.layout</field>
|
||||
<field name="view_ids"
|
||||
eval="[(5, 0, 0),
|
||||
(0, 0, {'view_mode': 'form', 'view_id': ref('product_label_layout_form')})]" />
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Loading…
Add table
Add a link
Reference in a new issue