Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
1
pricelist_cache/wizards/__init__.py
Executable file
1
pricelist_cache/wizards/__init__.py
Executable file
@@ -0,0 +1 @@
|
||||
from . import pricelist_cache_wizard
|
||||
59
pricelist_cache/wizards/pricelist_cache_wizard.py
Executable file
59
pricelist_cache/wizards/pricelist_cache_wizard.py
Executable file
@@ -0,0 +1,59 @@
|
||||
# Copyright 2021 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class PricelistCacheWizard(models.TransientModel):
|
||||
_name = "product.pricelist.cache.wizard"
|
||||
_description = "Wizard for pricelist cache"
|
||||
|
||||
partner_id = fields.Many2one("res.partner")
|
||||
pricelist_id = fields.Many2one("product.pricelist")
|
||||
product_id = fields.Many2one("product.product")
|
||||
display_cache_line_ids = fields.Many2many(
|
||||
"product.pricelist.cache", string="Cached prices"
|
||||
)
|
||||
|
||||
@api.onchange("partner_id")
|
||||
def _onchange_partner_id(self):
|
||||
if self.partner_id:
|
||||
self.pricelist_id = self.partner_id.property_product_pricelist
|
||||
else:
|
||||
self.pricelist_id = False
|
||||
|
||||
@api.onchange("pricelist_id", "product_id")
|
||||
def _onchange_product_pricelist(self):
|
||||
pricelist = self.pricelist_id
|
||||
product = self.product_id
|
||||
partner = self.partner_id
|
||||
if not pricelist:
|
||||
self.display_cache_line_ids = False
|
||||
return
|
||||
if product:
|
||||
products = product
|
||||
else:
|
||||
products = self.env["product.product"].search([])
|
||||
if partner and not partner.property_product_pricelist == pricelist:
|
||||
partner = False
|
||||
cache_model = self.env["product.pricelist.cache"]
|
||||
cache_selfs = cache_model.get_cached_prices_for_pricelist(
|
||||
self.pricelist_id, products
|
||||
)
|
||||
# TODO fields are flushed when get_cached_prices_for_pricelist
|
||||
# is called. I wonder is this is because of the use of flush()
|
||||
# in the code.
|
||||
# There's maybe a better way to keep those fields values.
|
||||
data = {
|
||||
"display_cache_line_ids": [(6, 0, cache_selfs.ids)],
|
||||
"pricelist_id": pricelist.id,
|
||||
"product_id": product.id if product else False,
|
||||
"partner_id": partner.id if partner else False,
|
||||
}
|
||||
self.update(data)
|
||||
|
||||
def open_in_tree_view(self):
|
||||
prices = self.display_cache_line_ids
|
||||
cache_model = self.env["product.pricelist.cache"]
|
||||
domain = [("id", "in", prices.ids)]
|
||||
return cache_model._get_tree_view(domain)
|
||||
55
pricelist_cache/wizards/pricelist_cache_wizard.xml
Executable file
55
pricelist_cache/wizards/pricelist_cache_wizard.xml
Executable file
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2021 Camptocamp SA
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
<record id="product_pricelist_cache_wizard_view_form" model="ir.ui.view">
|
||||
<field name="name">product.pricelist.cache.wizard.form</field>
|
||||
<field name="model">product.pricelist.cache.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Pricelist Cache">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="partner_id" />
|
||||
<field name="pricelist_id" />
|
||||
<field name="product_id" />
|
||||
<field name="display_cache_line_ids" mode="list">
|
||||
<list limit="80">
|
||||
<field name="product_id" />
|
||||
<field name="price" />
|
||||
</list>
|
||||
</field>
|
||||
</group>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button
|
||||
name="open_in_tree_view"
|
||||
type="object"
|
||||
string="Open"
|
||||
class="btn-primary"
|
||||
invisible="not display_cache_line_ids"
|
||||
/>
|
||||
<button special="cancel" string="Cancel" class="btn-default" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_pricelist_cache_wizard_action" model="ir.actions.act_window">
|
||||
<field name="name">Pricelist Cache</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">product.pricelist.cache.wizard</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="view_id" ref="product_pricelist_cache_wizard_view_form" />
|
||||
<field
|
||||
name="context"
|
||||
>{"withControlPanel": False, "no_breadcrumbs": True}</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
action="product_pricelist_cache_wizard_action"
|
||||
id="menuitem_pricelist_cache_wizard"
|
||||
parent="sale.prod_config_main"
|
||||
sequence="20"
|
||||
/>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user