19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:32:12 +01:00
parent 79f83631d5
commit 73afc09215
6267 changed files with 1534193 additions and 1130106 deletions

View file

@ -1,3 +1,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import product_label_layout
from . import update_product_attribute_value

View file

@ -16,20 +16,21 @@ class ProductLabelLayout(models.TransientModel):
('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)
custom_quantity = fields.Integer('Copies', 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')
pricelist_id = fields.Many2one('product.pricelist', string="Pricelist")
@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)
wizard.columns = columns.isdigit() and int(columns) or 1
wizard.rows = rows.isdigit() and int(rows) or 1
else:
wizard.columns, wizard.rows = 1, 1
@ -41,7 +42,9 @@ class ProductLabelLayout(models.TransientModel):
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'
xml_id = 'product.report_product_template_label_%sx%s' % (self.columns, self.rows)
if 'xprice' not in self.print_format:
xml_id += '_noprice'
else:
xml_id = ''
@ -69,6 +72,6 @@ class ProductLabelLayout(models.TransientModel):
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 = self.env.ref(xml_id).report_action(None, data=data, config=False)
report_action.update({'close_on_report_download': True})
return report_action

View file

@ -14,11 +14,12 @@
<field name="print_format" widget="radio"/>
</group>
<group>
<field name="extra_html" widget="html" attrs="{'invisible': [('print_format', '!=', '2x7xprice')]}"/>
<field name="pricelist_id" groups="product.group_product_pricelist"/>
<field name="extra_html" invisible="print_format != '2x7xprice'"/>
</group>
</group>
<footer>
<button name="process" string="Confirm" type="object" class="btn-primary"/>
<button name="process" string="Print" type="object" class="btn-primary"/>
<button string="Discard" class="btn-secondary" special="cancel"/>
</footer>
</form>
@ -26,7 +27,7 @@
</record>
<record id="action_open_label_layout" model="ir.actions.act_window">
<field name="name">Choose Labels Layout</field>
<field name="name">Print Labels</field>
<field name="res_model">product.label.layout</field>
<field name="view_ids"
eval="[(5, 0, 0),

View file

@ -0,0 +1,73 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import _, api, fields, models
from odoo.fields import Command
class UpdateProductAttributeValue(models.TransientModel):
_name = 'update.product.attribute.value'
_description = "Update product attribute value"
attribute_value_id = fields.Many2one('product.attribute.value', required=True)
mode = fields.Selection(
selection=[
('add', "Add to existing products"),
('update_extra_price', "Update the extra price on existing products")
]
)
message = fields.Char(compute='_compute_message')
product_count = fields.Integer(compute='_compute_product_count')
@api.depends('product_count', 'mode', 'attribute_value_id')
def _compute_message(self):
self.message = ''
for wizard in self:
if wizard.mode == 'add':
wizard.message = _(
"You are about to add the value \"%(attribute_value)s\" to %(product_count)s products.",
attribute_value=wizard.attribute_value_id.name,
product_count=wizard.product_count,
)
elif wizard.mode == 'update_extra_price':
wizard.message = _(
"You are about to update the extra price of %s products.",
wizard.product_count,
)
@api.depends('mode')
def _compute_product_count(self):
self.product_count = 0
ProductTemplate = self.env['product.template']
for wizard in self:
if wizard.mode == 'add':
wizard.product_count = ProductTemplate.search_count([
('attribute_line_ids.attribute_id', '=', wizard.attribute_value_id.attribute_id.id),
])
elif wizard.mode == 'update_extra_price':
wizard.product_count = ProductTemplate.search_count([
('attribute_line_ids.value_ids', '=', wizard.attribute_value_id.id),
])
def action_confirm(self):
self.ensure_one()
if self.mode == 'add':
self._add_value_to_existing_attribute_lines()
elif self.mode == 'update_extra_price':
self._update_extra_price_on_existing_products()
def _add_value_to_existing_attribute_lines(self):
ptals = self.env['product.template.attribute.line'].search([
('attribute_id', '=', self.attribute_value_id.attribute_id.id),
# Make sure we do not impact products belonging to other companies
('product_tmpl_id.company_id', 'in', self.env.companies.ids + [False]),
])
ptals.write({'value_ids': [Command.link(self.attribute_value_id.id)]})
def _update_extra_price_on_existing_products(self):
ptavs = self.env['product.template.attribute.value'].search([
('product_attribute_value_id', '=', self.attribute_value_id.id),
# Make sure we do not impact products belonging to other companies
('product_tmpl_id.company_id', 'in', self.env.companies.ids + [False]),
])
ptavs.write({'price_extra': self.attribute_value_id.default_extra_price})

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="update_product_attribute_value_form" model="ir.ui.view">
<field name="name">update.product.attribute.value.form</field>
<field name="model">update.product.attribute.value</field>
<field name="arch" type="xml">
<form>
<field name="product_count" invisible="1"/>
<field name="mode" invisible="1"/>
<field name="message"/>
<footer>
<button string="Cancel" special="cancel"/>
<button
name="action_confirm"
string="Confirm"
class="btn-primary"
type="object"
/>
</footer>
</form>
</field>
</record>
</odoo>