-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance pos_margin module with v12 version
- Loading branch information
fjg
committed
Nov 19, 2020
1 parent
d75b7f6
commit c376b08
Showing
96 changed files
with
4,633 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
from . import pos_order | ||
from . import pos_order_line | ||
from . import report_pos_order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# -*- coding: utf-8 -*- | ||
from openerp import fields, models | ||
from openerp import tools | ||
|
||
|
||
class ReportPosOrder(models.Model): | ||
_inherit = "report.pos.order" | ||
|
||
margin_total = fields.Float(string='Margin Total') | ||
margin_rate = fields.Float(string='Margin Rate', group_operator='avg') | ||
|
||
def init(self, cr): | ||
tools.drop_view_if_exists(cr, 'report_pos_order') | ||
cr.execute(""" | ||
create or replace view report_pos_order as ( | ||
select | ||
min(l.id) as id, | ||
count(*) as nbr, | ||
s.date_order as date, | ||
s.id as order_id, | ||
sum(l.qty) as product_qty, | ||
sum(l.price_subtotal) as price_total_vat_excl, | ||
sum(l.qty * l.price_unit) as price_sub_total, | ||
sum((l.qty * l.price_unit) * (100 - l.discount) / 100) | ||
as price_total, | ||
sum((l.qty * l.price_unit) * (l.discount / 100)) | ||
as total_discount, | ||
(sum(l.qty*l.price_unit)/sum(l.qty * u.factor))::decimal | ||
as average_price, | ||
sum(cast(to_char(date_trunc('day',s.date_order) | ||
- date_trunc('day',s.create_date),'DD') as int)) | ||
as delay_validation, | ||
s.partner_id as partner_id, | ||
s.state as state, | ||
s.user_id as user_id, | ||
s.location_id as location_id, | ||
s.company_id as company_id, | ||
s.sale_journal as journal_id, | ||
l.product_id as product_id, | ||
pt.categ_id as product_categ_id, | ||
p.product_tmpl_id, | ||
ps.config_id, | ||
pt.pos_categ_id, | ||
pc.stock_location_id, | ||
s.pricelist_id, | ||
s.invoice_id IS NOT NULL AS invoiced, | ||
sum(l.margin) as margin_total, | ||
(sum(l.margin / nullif(l.qty,0)) * 100 / | ||
sum(nullif(l.purchase_price,0)))::decimal as margin_rate | ||
from pos_order_line as l | ||
left join pos_order s on (s.id=l.order_id) | ||
left join product_product p on (l.product_id=p.id) | ||
left join product_template pt on (p.product_tmpl_id=pt.id) | ||
left join product_uom u on (u.id=pt.uom_id) | ||
left join pos_session ps on (s.session_id=ps.id) | ||
left join pos_config pc on (ps.config_id=pc.id) | ||
group by | ||
s.id, s.date_order, s.partner_id,s.state, pt.categ_id, | ||
s.user_id,s.location_id,s.company_id,s.sale_journal, | ||
s.pricelist_id,s.invoice_id,l.product_id,s.create_date, | ||
pt.categ_id,pt.pos_categ_id,p.product_tmpl_id, | ||
ps.config_id,pc.stock_location_id | ||
having | ||
sum(l.qty * u.factor) != 0)""") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<odoo> | ||
<record id="view_report_pos_order_pivot_margin_inherit" model="ir.ui.view"> | ||
<field name="name">report.pos.order.pivot.inherit</field> | ||
<field name="model">report.pos.order</field> | ||
<field name="inherit_id" ref="point_of_sale.view_report_pos_order_pivot"/> | ||
<field name="arch" type="xml"> | ||
<field name="price_total" position="after"> | ||
<field name="margin_total" type="measure"/> | ||
<field name="margin_rate" type="measure"/> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> | ||
</openerp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from functools import partial | ||
import openerp | ||
from openerp import api, SUPERUSER_ID | ||
|
||
import sale_margin # noqa | ||
import report # noqa | ||
|
||
|
||
def uninstall_hook(cr, registry): | ||
def recreate_view(dbname): | ||
db_registry = openerp.modules.registry.RegistryManager.new(dbname) | ||
with api.Environment.manage(), db_registry.cursor() as cr: | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
if 'sale.report' in env: | ||
env['sale.report'].init() | ||
|
||
cr.after("commit", partial(recreate_view, cr.dbname)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
{ | ||
'name': 'Margins in Sales Orders', | ||
'version':'1.0', | ||
'category': 'Sales', | ||
'description': """ | ||
This module adds the 'Margin' on sales order. | ||
============================================= | ||
This gives the profitability by calculating the difference between the Unit | ||
Price and Cost Price. | ||
""", | ||
'author':'OpenERP SA', | ||
'depends':['sale'], | ||
'demo':['sale_margin_demo.xml'], | ||
'test': ['test/sale_margin.yml'], | ||
'data':['security/ir.model.access.csv','sale_margin_view.xml'], | ||
'auto_install': False, | ||
'installable': True, | ||
'uninstall_hook': "uninstall_hook", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * sale_margin | ||
# | ||
# Translators: | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo 9.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2015-09-07 14:41+0000\n" | ||
"PO-Revision-Date: 2015-08-25 10:24+0000\n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: Afrikaans (http://www.transifex.com/odoo/odoo-9/language/af/)\n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Language: af\n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
|
||
#. module: sale_margin | ||
#: model:ir.model.fields,field_description:sale_margin.field_sale_order_line_purchase_price | ||
msgid "Cost" | ||
msgstr "Koste" | ||
|
||
#. module: sale_margin | ||
#: model:ir.model.fields,help:sale_margin.field_sale_order_margin | ||
msgid "" | ||
"It gives profitability by calculating the difference between the Unit Price " | ||
"and the cost." | ||
msgstr "" | ||
|
||
#. module: sale_margin | ||
#: model:ir.model.fields,field_description:sale_margin.field_sale_order_line_margin | ||
#: model:ir.model.fields,field_description:sale_margin.field_sale_order_margin | ||
#: model:ir.model.fields,field_description:sale_margin.field_sale_report_margin | ||
msgid "Margin" | ||
msgstr "" | ||
|
||
#. module: sale_margin | ||
#: model:ir.model,name:sale_margin.model_sale_order | ||
msgid "Sales Order" | ||
msgstr "" | ||
|
||
#. module: sale_margin | ||
#: model:ir.model,name:sale_margin.model_sale_order_line | ||
msgid "Sales Order Line" | ||
msgstr "" | ||
|
||
#. module: sale_margin | ||
#: model:ir.model,name:sale_margin.model_sale_report | ||
msgid "Sales Orders Statistics" | ||
msgstr "" |
Oops, something went wrong.