Browse Source

Modif pack: affichage du bon prix sur site + gestion des stocks + affichage prix au kilo

12.0
Juliana 4 years ago
parent
commit
52ff3e361f
  1. 4
      __manifest__.py
  2. 3
      models/__init__.py
  3. 40
      models/product_template.py
  4. 15
      views/product_template_views.xml
  5. 32
      views/templates.xml

4
__manifest__.py

@ -13,6 +13,8 @@
],
"data": [
'security/ir.model.access.csv',
'report/sale_report.xml'
'report/sale_report.xml',
'views/product_template_views.xml',
'views/templates.xml'
]
}

3
models/__init__.py

@ -1,4 +1,5 @@
# © 2019 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import sale_order
from . import sale_order
from . import product_template

40
models/product_template.py

@ -0,0 +1,40 @@
# © 2020 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.addons import decimal_precision as dp
class ProductTemplate(models.Model):
_inherit = 'product.template'
list_price_ref_pack = fields.Float(
'Prix référent au kilo', default=1.0,
digits=dp.get_precision('Product Price'),
compute='_compute_list_price_ref_pack')
price_ref_pack_compute = fields.Float(
'Prix calculé', default=1.0,
digits=dp.get_precision('Product Price'),
compute='_compute_price_ref_pack_compute')
def _compute_list_price_ref_pack(self):
for template in self:
if template.pack_line_ids:
if template.pack_ok and (template.pack_type == 'detailed' and template.pack_component_price == 'totalized'):
pack_price_ref = 0.0
for pack_line in template.pack_line_ids:
pack_price_ref += pack_line.product_id.list_price
template.list_price_ref_pack = pack_price_ref
# template.list_price_ref_pack = template.pack_line_ids[0].product_id.list_price
def _compute_price_ref_pack_compute(self):
for template in self:
if template.pack_line_ids:
if template.pack_ok and (template.pack_type == 'detailed' and template.pack_component_price == 'totalized'):
pack_price = 0.0
for pack_line in template.pack_line_ids:
pack_price += pack_line.product_id.list_price * pack_line.quantity
template.price_ref_pack_compute = pack_price

15
views/product_template_views.xml

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="product_template_form_view" model="ir.ui.view">
<field name="name">product.template.pack.form</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<field name="list_price" position="after">
<field name="list_price_ref_pack" string="Prix produit référent au kg" widget='monetary' options="{'currency_field': 'currency_id', 'field_digits': True}" attrs="{'invisible': [('pack_ok', '!=', True)]}"/>
<field name="price_ref_pack_compute" string="Prix de vente TTC" widget='monetary' options="{'currency_field': 'currency_id', 'field_digits': True}" attrs="{'invisible': [('pack_ok', '!=', True)]}"/>
</field>
</field>
</record>
</odoo>

32
views/templates.xml

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="product_price" inherit_id="website_sale.product_price">
<xpath expr="//h4" position="after">
<t t-if="product.pack_ok">
<h5><span t-esc="product.list_price_ref_pack" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/><span> / kilo</span></h5>
</t>
</xpath>
</template>
<template id="products_item" inherit_id="website_sale.products_item">
<xpath expr="//div[hasclass('product_price')]" position="replace">
<div itemprop="offers" itemscope="itemscope" itemtype="http://schema.org/Offer" class="product_price">
<b>
<t t-if="True"><!-- compatibility 12.0 -->
<del t-attf-class="text-danger mr8 {{'' if combination_info['has_discounted_price'] else 'd-none'}}" style="white-space: nowrap;" t-esc="combination_info['list_price']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}" />
</t>
<t t-if="product.pack_ok">
<span t-esc="product.price_ref_pack_compute" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
</t>
<t t-else="">
<span t-if="combination_info['price']" t-esc="combination_info['price']" t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"/>
<span itemprop="price" style="display:none;" t-esc="combination_info['price']" />
<span itemprop="priceCurrency" style="display:none;" t-esc="website.currency_id.name" />
</t>
</b>
</div>
</xpath>
</template>
</odoo>
Loading…
Cancel
Save