Browse Source

[ADD] percent margin on pos.order and pos.order.line (following same logic as OCA/margin-analysis/account_invoice_margin module ; [ADD] margin and margin percent on tree pos order view ; [UPD] Description and translation

pull/423/head
Sylvain LE GAL 4 years ago
parent
commit
f4badd2217
  1. 1
      pos_margin/__manifest__.py
  2. 21
      pos_margin/models/pos_order.py
  3. 30
      pos_margin/models/pos_order_line.py
  4. 6
      pos_margin/readme/USAGE.rst
  5. BIN
      pos_margin/static/description/pos_order_form.png
  6. BIN
      pos_margin/static/description/pos_order_tree.png
  7. 8
      pos_margin/views/view_pos_order.xml

1
pos_margin/__manifest__.py

@ -9,6 +9,7 @@
'category': 'Point Of Sale',
'author': "GRAP,"
"Odoo Community Association (OCA)",
"maintainers": ["legalsylvain"],
'website': 'https://github.com/OCA/pos',
'license': 'AGPL-3',
'depends': [

21
pos_margin/models/pos_order.py

@ -11,14 +11,29 @@ class PosOrder(models.Model):
# Columns Section
margin = fields.Float(
'Margin', compute='_compute_margin', store=True,
string='Margin',
compute='_compute_margin',
store=True,
digits=dp.get_precision('Product Price'),
help="It gives profitability by calculating the difference between"
" the Unit Price and the cost price.")
margin_percent = fields.Float(
string='Margin (%)',
compute='_compute_margin',
store=True,
digits=dp.get_precision('Product Price'),
)
# Compute Section
@api.multi
@api.depends('lines.margin')
@api.depends('lines.margin', 'lines.price_subtotal')
def _compute_margin(self):
for order in self:
order.margin = sum(order.mapped('lines.margin'))
tmp_margin = sum(order.mapped('lines.margin'))
tmp_price_subtotal = sum(order.mapped('lines.price_subtotal'))
order.update({
'margin': tmp_margin,
'margin_percent': tmp_price_subtotal and (
tmp_margin / tmp_price_subtotal * 100),
})

30
pos_margin/models/pos_order_line.py

@ -11,12 +11,25 @@ class PosOrderLine(models.Model):
# Columns Section
margin = fields.Float(
'Margin', compute='_compute_multi_margin', store=True,
multi='multi_margin', digits=dp.get_precision('Product Price'))
string='Margin',
compute='_compute_multi_margin',
store=True,
digits=dp.get_precision('Product Price'),
)
margin_percent = fields.Float(
string='Margin (%)',
compute='_compute_multi_margin',
store=True,
digits=dp.get_precision('Product Price'),
)
purchase_price = fields.Float(
'Cost Price', compute='_compute_multi_margin', store=True,
multi='multi_margin', digits=dp.get_precision('Product Price'))
string='Cost Price',
compute='_compute_multi_margin',
store=True,
digits=dp.get_precision('Product Price'),
)
# Compute Section
@api.multi
@ -24,8 +37,13 @@ class PosOrderLine(models.Model):
def _compute_multi_margin(self):
for line in self.filtered('product_id'):
purchase_price = self._get_purchase_price(line)
line.purchase_price = purchase_price
line.margin = line.price_subtotal - (purchase_price * line.qty)
margin = line.price_subtotal - (purchase_price * line.qty)
line.update({
'purchase_price': purchase_price,
'margin': margin,
'margin_percent': line.price_subtotal and (
margin / line.price_subtotal * 100.0),
})
@api.model
def _get_purchase_price(self, line):

6
pos_margin/readme/USAGE.rst

@ -1,7 +1,13 @@
To use this module, you need to:
* Go to 'Point Of Sale' / 'Orders' / 'Orders'
.. figure:: ../static/description/pos_order_tree.png
:width: 800px
* Open an order
.. figure:: ../static/description/pos_order_form.png
:width: 800px

BIN
pos_margin/static/description/pos_order_form.png

Before

Width: 896  |  Height: 379  |  Size: 30 KiB

After

Width: 1122  |  Height: 500  |  Size: 69 KiB

BIN
pos_margin/static/description/pos_order_tree.png

After

Width: 1031  |  Height: 206  |  Size: 51 KiB

8
pos_margin/views/view_pos_order.xml

@ -13,9 +13,12 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="arch" type="xml">
<field name="amount_total" position="after">
<field name="margin" widget="monetary"/>
<field name="margin_percent" widget="monetary"/>
</field>
<xpath expr="//field[@name='lines']/tree/field[@name='price_unit']" position="after">
<xpath expr="//field[@name='lines']/tree/field[@name='discount']" position="after">
<field name="purchase_price" widget="monetary"/>
<field name="margin"/>
<field name="margin_percent"/>
</xpath>
</field>
</record>
@ -25,7 +28,8 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="inherit_id" ref="point_of_sale.view_pos_order_tree"/>
<field name="arch" type="xml">
<field name="amount_total" position="before">
<field name="margin" widget="monetary" sum="Margin Total"/>
<field name="margin" widget="monetary" sum="Total"/>
<field name="margin_percent" widget="monetary"/>
</field>
</field>
</record>

Loading…
Cancel
Save