Skip to content

Commit

Permalink
[IMP] Adds funcionaly "by margin" that has the product_sale_price_by_…
Browse files Browse the repository at this point in the history
…margin module
  • Loading branch information
nicomacr committed Jun 28, 2018
1 parent b93d26a commit 3b50358
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 10 deletions.
8 changes: 6 additions & 2 deletions product_planned_price/README.rst
Expand Up @@ -14,7 +14,10 @@
Product Planned Price
=====================

This module add a new field "Planned Price" to products that can be extended by other modules to calculte this prices based in different conditions. It also add a wizard to update "List Price" using "Planned Price" value. Optionally, you can activate a cron to run this update auomatically.
This module add a new field "Planned Price" to products that can be extended by other modules to calculte this prices based in different conditions.

#. It also add a wizard to update "List Price" using "Planned Price" value. Optionally, you can activate a cron to run this update auomatically.
#. Also Extends Planned Price and allow to set prices based on Replenishment Cost with a fixed and/or percentage margin.

Installation
============
Expand All @@ -29,13 +32,14 @@ Configuration
To configure this module, you need to:

#. Go to Pricelist/Pricelist Items/ config "Base" to "Computed List Price".
#. Go to any product template and define the method to compute the Planned Price.

Usage
=====

To use this module, you need to:

#. Go to Product Template and set the planned price
#. Go to Product Template and set the planned price "based on" to set by different methods to compute this price.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
Expand Down
2 changes: 1 addition & 1 deletion product_planned_price/__manifest__.py
Expand Up @@ -28,7 +28,7 @@
'images': [
],
'depends': [
'product',
'product_replenishment_cost',
],
'data': [
'views/product_template_views.xml',
Expand Down
11 changes: 11 additions & 0 deletions product_planned_price/demo/product_product_demo.xml
Expand Up @@ -8,4 +8,15 @@
<field name="list_price_type">manual</field>
<field name="type">service</field>
</record>
<record id="computed_by_margin" model="product.product">
<field name="name">Computed by Margin Product</field>
<field name="categ_id" ref="product.product_category_4"/>
<field name="replenishment_base_cost">50</field>
<field name="replenishment_base_cost_currency_id" ref="base.USD"/>
<field name="standard_price">60</field>
<field name="sale_margin">50</field>
<field name="sale_surcharge">10</field>
<field name="list_price_type">by_margin</field>
<field name="type">service</field>
</record>
</odoo>
41 changes: 34 additions & 7 deletions product_planned_price/models/product_template.py
Expand Up @@ -24,11 +24,29 @@ class ProductTemplate(models.Model):
'other parameters.',
)
list_price_type = fields.Selection([
('manual', 'Fixed value')],
('manual', 'Fixed value'),
('by_margin', 'By Margin')
],
string='Planned Price Type',
# we make it optional
# required=True,
default='manual',
help="If the 'Fixed value' type is chosen, a fixed planned"
" price is defined. \n If the 'By margin' type is chosen, "
"the following formula will be taken into account for "
"the planned price: Replenishment cost * (1 + margin(%)) + surcharge.",
)
sale_margin = fields.Float(
'Planned Price Sale margin %',
digits=dp.get_precision('Discount'),
)
sale_surcharge = fields.Float(
'Planned Price Sale surcharge',
digits=dp.get_precision('Product Price')
)
replenishment_cost_copy = fields.Float(
related='replenishment_cost'
# related='product_variant_ids.replenishment_cost'
)

@api.model
Expand Down Expand Up @@ -89,16 +107,25 @@ def _update_prices_from_planned(self):
return True

@api.depends(
'sale_margin',
'sale_surcharge',
'replenishment_cost',
'list_price_type',
'computed_list_price_manual',
)
def _compute_computed_list_price(self):
manual_recs = self.filtered(
lambda x: x.list_price_type == 'manual')
_logger.info('Get computed_list_price for %s "manual" products' % (
len(manual_recs)))
for rec in manual_recs:
rec.update({'computed_list_price': rec.computed_list_price_manual})
recs = self.filtered(
lambda x: x.list_price_type in ['manual', 'by_margin'])
_logger.info('Get computed_list_price for %s "manual" and "by_margin"'
' products' % (len(recs)))
for rec in recs:
computed_list_price = rec.computed_list_price_manual\
if rec.list_price_type == 'manual'\
else rec.replenishment_cost * \
(1 + rec.sale_margin / 100.0) + rec.sale_surcharge
rec.update({
'computed_list_price': computed_list_price,
})

@api.model
def _price_get(self, products, ptype='list_price'):
Expand Down
6 changes: 6 additions & 0 deletions product_planned_price/views/product_template_views.xml
Expand Up @@ -23,6 +23,12 @@
<group name="pricing">
<group name="planned_price">
<field name="list_price_type" string="Planned Price based on"/>
<label for="sale_margin" string="Margin Formula" attrs="{'invisible': [('list_price_type', '!=', 'by_margin')]}"/>
<div attrs="{'invisible': [('list_price_type', '!=', 'by_margin')]}">
<field name="replenishment_cost_copy" class="oe_inline"/>* ( 1 +
<field name="sale_margin" class="oe_inline"/>%) +
<field name="sale_surcharge" class="oe_inline"/>
</div>
<field name="computed_list_price_manual" widget="monetary" attrs="{'invisible': [('list_price_type', '!=', 'manual')]}" string="Planned Price" options="{'currency_field': 'currency_id'}"/>
<field name="computed_list_price" widget="monetary" attrs="{'invisible': [('list_price_type', 'in', ['manual', False])]}" options="{'currency_field': 'currency_id'}"/>
</group>
Expand Down

0 comments on commit 3b50358

Please sign in to comment.