Browse Source

Dec 16 : [UPDT] Updated 'margin_product_sale_invoice'

pull/295/head
AjmalCybro 1 year ago
parent
commit
6ec25a483f
  1. 3
      margin_product_sale_invoice/__manifest__.py
  2. 1
      margin_product_sale_invoice/models/__init__.py
  3. 18
      margin_product_sale_invoice/models/account_move.py
  4. 7
      margin_product_sale_invoice/models/product_product.py
  5. 40
      margin_product_sale_invoice/models/product_template.py
  6. 21
      margin_product_sale_invoice/models/sale_order.py
  7. 14
      margin_product_sale_invoice/views/product_template_views.xml

3
margin_product_sale_invoice/__manifest__.py

@ -21,7 +21,7 @@
#############################################################################
{
'name': 'Margin on Products, Sales & Invoices',
'version': '16.0.1.0.0',
'version': '16.0.1.0.3',
'summary': 'Providing margin on products, sales and invoices',
'sequence': 4,
'description': """This module is developed to help to provide the
@ -39,6 +39,7 @@
],
'data': [
'report/sale_report_views.xml',
'views/product_template_views.xml',
'views/product_product_views.xml',
'views/sale_order_views.xml',
'views/account_move_views.xml',

1
margin_product_sale_invoice/models/__init__.py

@ -20,5 +20,6 @@
#
#############################################################################
from . import product_product
from . import product_template
from . import sale_order
from . import account_move

18
margin_product_sale_invoice/models/account_move.py

@ -27,7 +27,7 @@ class AccountMoveLine(models.Model):
_inherit = 'account.move.line'
cost_price_amount = fields.Float(string='Cost',
related="product_id.standard_price",
compute='compute_cost_price_amount',
store=True, help='Field for the cost')
margin_amount = fields.Float(string='Margin Amount',
compute='compute_margin_amount',
@ -42,13 +42,25 @@ class AccountMoveLine(models.Model):
if record.price_unit and record.cost_price_amount:
record.margin_amount = record.price_unit - record.cost_price_amount
@api.depends('product_id')
def compute_cost_price_amount(self):
for record in self:
converted_amount = record.env.company.currency_id._convert(
from_amount=record.product_id.standard_price,
to_currency=record.currency_id, company=record.company_id,
date=fields.Date.today()
)
record.cost_price_amount = converted_amount
class AccountMove(models.Model):
"""This class extends for margin on the invoices"""
_inherit = 'account.move'
margin_percent_amount = fields.Float(string='Margin %', help='Field margin amount in percentage')
margin_amount_total = fields.Float(string='Margin Amount', help='Field displays total margin amount')
margin_percent_amount = fields.Float(string='Margin %',
help='Field margin amount in percentage')
margin_amount_total = fields.Float(string='Margin Amount',
help='Field displays total margin amount')
def action_post(self):
"""Method for setting the margin amount and margin percent"""

7
margin_product_sale_invoice/models/product_product.py

@ -26,12 +26,13 @@ class ProductProduct(models.Model):
"""This class represents margin on products"""
_inherit = 'product.product'
margin_percent_product = fields.Float(string='Margin %', compute='compute_margin', store=True,
help='Field to store the margin in percentage of the product')
margin_percent_product = fields.Float(string='Margin %',
compute='compute_margin', store=True,
help='Field to store the margin in'
' percentage of the product')
@api.depends('list_price', 'standard_price')
def compute_margin(self):
"""Method to compute the margin of the product."""
self.margin_percent_product = 0
for record in self:
if record.list_price and record.standard_price:

40
margin_product_sale_invoice/models/product_template.py

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
#############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
#
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
#
# You can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
#############################################################################
from odoo import api, fields, models
class ProductTemplate(models.Model):
"""This class represents margin on products"""
_inherit = 'product.template'
margin_percent_product = fields.Float(string='Margin %',
compute='compute_margin', store=True,
help='Field to store the margin in'
' percentage of the product')
@api.depends('list_price', 'standard_price')
def compute_margin(self):
"""Method to compute the margin of the product."""
self.margin_percent_product = 0
for record in self:
if record.list_price and record.standard_price:
record.margin_percent_product = ( record.list_price - record.standard_price) / record.list_price

21
margin_product_sale_invoice/models/sale_order.py

@ -27,7 +27,7 @@ class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
cost_price_sale = fields.Float(string='Cost',
related='product_id.standard_price',
compute='compute_cost_price_amount',
store=True, help='Field for cost price')
margin_amount_sale = fields.Float(string='Margin Amount',
compute='compute_margin_amount',
@ -42,6 +42,16 @@ class SaleOrderLine(models.Model):
if record.product_id:
record.cost_price_sale = record.product_id.standard_price
@api.depends('product_id')
def compute_cost_price_amount(self):
for record in self:
converted_amount = record.product_id.currency_id._convert(
from_amount=record.product_id.standard_price,
to_currency=record.env.company.currency_id, company=record.company_id,
date=fields.Date.today()
)
record.cost_price_sale = converted_amount
@api.depends('product_id')
def compute_margin_amount(self):
""" Compute the margin amount of the line. """
@ -55,8 +65,10 @@ class SaleOrder(models.Model):
"""This class is used to display margin on sale order."""
_inherit = 'sale.order'
margin_percent_sale = fields.Float(string='Margin %', help='Field for margin in percentage')
margin_amount_sale_total = fields.Float(string='Margin Amount', help='Field for Margin amount in total ')
margin_percent_sale = fields.Float(string='Margin %',
help='Field for margin in percentage')
margin_amount_sale_total = fields.Float(string='Margin Amount',
help='Field for Margin amount in total ')
def action_confirm(self):
"""Method for confirm sale order and set values to margin and margin
@ -64,6 +76,7 @@ class SaleOrder(models.Model):
res = super(SaleOrder, self).action_confirm()
for record in self:
if record.order_line.product_id:
record.margin_amount_sale_total = sum(record.order_line.mapped('margin_amount_sale'))
record.margin_amount_sale_total = sum(
record.order_line.mapped('margin_amount_sale'))
record.margin_percent_sale = record.margin_amount_sale_total / record.amount_total
return res

14
margin_product_sale_invoice/views/product_template_views.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!--Inherited the product template form view-->
<record id="product_template_only_form_view" model="ir.ui.view">
<field name="name">product.template.view.form.inherit.margin.product.sale.invoice</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='detailed_type']" position="after">
<field name="margin_percent_product" widget="percentage" groups="!product.group_product_variant"/>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save