Improvement on product_margin

* remove sale & purchase dependacy
* graph view for turnover , total cost
* add a sum="..." on the fields: turnover, total margin, sales gap
in the tree
* By default the wizard propose to report on the latest year. (not empty
fields)

The title of the tab must be Margins instead of Margin. Put tooltips on
all fields that explain how they are computed.
* made new form view and set high priority
* modify states : (paid,open_paid,draft_open_paid)

bzr revid: hmo@tinyerp.com-20081010122744-5sw8yfbopt0zr04k
This commit is contained in:
Harshad Modi 2008-10-10 17:57:44 +05:30
parent 8ebb7ae477
commit 7fa0283232
4 changed files with 69 additions and 52 deletions

View File

@ -4,7 +4,7 @@
"version":"1.0",
"author":"Tiny",
"category":"Custom",
"depends":["product"],
"depends":["base","product","account"],
"demo_xml":[],
"update_xml":["product_margin_view.xml"],
"active": False,

View File

@ -43,7 +43,7 @@ class product_product(osv.osv):
res[val.id] = {}
date_from=context.get('date_from', time.strftime('%Y-01-01'))
date_to=context.get('date_to', time.strftime('%Y-12-31'))
invoice_state=context.get('invoice_state', 'open')
invoice_state=context.get('invoice_state', 'open_paid')
if 'date_from' in field_names:
res[val.id]['date_from']=date_from
if 'date_to' in field_names:
@ -54,12 +54,12 @@ class product_product(osv.osv):
invoice_types=[]
states=[]
if invoice_state=='draft_open':
states=['draft','open']
elif invoice_state=='paid':
if invoice_state=='paid':
states=['paid']
elif invoice_state=='open':
states=['open']
elif invoice_state=='open_paid':
states=['open','paid']
elif invoice_state=='draft_open_paid':
states=['draft','open','paid']
if 'sale_avg_price' in field_names or 'sale_num_invoiced' in field_names or 'turnover' in field_names or 'sale_expected' in field_names:
invoice_types=['out_invoice','in_refund']
@ -71,15 +71,11 @@ class product_product(osv.osv):
avg(l.price_unit) as avg_unit_price,
sum(l.quantity) as num_qty,
sum(l.quantity * l.price_unit) as total,
sum(sale_line.product_uom_qty * sale_line.price_unit) as sale_expected,
sum(purchase_line.product_qty * purchase_line.price_unit) as normal_cost
sum(l.quantity * product.list_price) as sale_expected,
sum(l.quantity * product.standard_price) as normal_cost
from account_invoice_line l
left join account_invoice i on (l.invoice_id = i.id)
left join sale_order_invoice_rel sale_invoice on (i.id=sale_invoice.invoice_id)
left join sale_order sale on sale.id=sale_invoice.order_id
left join sale_order_line sale_line on sale.id=sale_line.order_id
left join purchase_order purchase on purchase.invoice_id=i.id
left join purchase_order_line purchase_line on purchase_line.order_id=purchase.id
left join product_template product on (product.id=l.product_id)
where l.product_id = %s and i.state in ('%s') and i.type in ('%s')
"""%(val.id,"','".join(states),"','".join(invoice_types))
cr.execute(sql)
@ -111,24 +107,22 @@ class product_product(osv.osv):
'date_from': fields.function(_product_margin, method=True, type='date', string='From Date', multi=True),
'date_to': fields.function(_product_margin, method=True, type='date', string='To Date', multi=True),
'invoice_state': fields.function(_product_margin, method=True, type='selection', selection=[
('paid','Paid'),
('open','All Open'),
('draft_open','Draft and Open')
('paid','Paid'),('open_paid','Open and Paid'),('draft_open_paid','Draft, Open and Paid')
], string='Invoice State',multi=True, readonly=True),
'sale_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='sale'),
'purchase_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='purchase'),
'sale_num_invoiced' : fields.function(_product_margin, method=True, type='float', string='# Invoiced', multi='sale'),
'purchase_num_invoiced' : fields.function(_product_margin, method=True, type='float', string='# Invoiced', multi='purchase'),
'sales_gap' : fields.function(_product_margin, method=True, type='float', string='Sales Gap', multi='sale'),
'purchase_gap' : fields.function(_product_margin, method=True, type='float', string='Purchase Gap', multi='purchase'),
'turnover' : fields.function(_product_margin, method=True, type='float', string='Turnover' ,multi='sale'),
'total_cost' : fields.function(_product_margin, method=True, type='float', string='Total Cost', multi='purchase'),
'sale_expected' : fields.function(_product_margin, method=True, type='float', string='Expected Sale', multi='sale'),
'normal_cost' : fields.function(_product_margin, method=True, type='float', string='Normal Cost', multi='purchase'),
'total_margin' : fields.function(_product_margin, method=True, type='float', string='Total Margin', multi='total'),
'expected_margin' : fields.function(_product_margin, method=True, type='float', string='Expected Margin', multi='total'),
'total_margin_rate' : fields.function(_product_margin, method=True, type='float', string='Total Margin (%)', multi='margin'),
'expected_margin_rate' : fields.function(_product_margin, method=True, type='float', string='Expected Margin (%)', multi='margin'),
'sale_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='sale',help="Avg. Price in Customer Invoices)"),
'purchase_avg_price' : fields.function(_product_margin, method=True, type='float', string='Avg. Unit Price', multi='purchase',help="Avg. Price in Supplier Invoices "),
'sale_num_invoiced' : fields.function(_product_margin, method=True, type='float', string='# Invoiced', multi='sale',help="Sum of Quantity in Customer Invoices"),
'purchase_num_invoiced' : fields.function(_product_margin, method=True, type='float', string='# Invoiced', multi='purchase',help="Sum of Quantity in Supplier Invoices"),
'sales_gap' : fields.function(_product_margin, method=True, type='float', string='Sales Gap', multi='sale',help="Excepted Sale - Turn Over"),
'purchase_gap' : fields.function(_product_margin, method=True, type='float', string='Purchase Gap', multi='purchase',help="Normal Cost - Total Cost"),
'turnover' : fields.function(_product_margin, method=True, type='float', string='Turnover' ,multi='sale',help="Sum of Multification of Invoice price and quantity of Customer Invoices"),
'total_cost' : fields.function(_product_margin, method=True, type='float', string='Total Cost', multi='purchase',help="Sum of Multification of Invoice price and quantity of Supplier Invoices "),
'sale_expected' : fields.function(_product_margin, method=True, type='float', string='Expected Sale', multi='sale',help="Sum of Multification of Sale Catalog price and quantity of Customer Invoices"),
'normal_cost' : fields.function(_product_margin, method=True, type='float', string='Normal Cost', multi='purchase',help="Sum of Multification of Cost price and quantity of Supplier Invoices"),
'total_margin' : fields.function(_product_margin, method=True, type='float', string='Total Margin', multi='total',help="Turnorder - Total Cost"),
'expected_margin' : fields.function(_product_margin, method=True, type='float', string='Expected Margin', multi='total',help="Excepted Sale - Normal Cost"),
'total_margin_rate' : fields.function(_product_margin, method=True, type='float', string='Total Margin (%)', multi='margin',help="Total margin * 100 / Turnover"),
'expected_margin_rate' : fields.function(_product_margin, method=True, type='float', string='Expected Margin (%)', multi='margin',help="Expected margin * 100 / Expected Sale"),
}

View File

@ -2,21 +2,38 @@
<openerp>
<data>
<wizard id="action_open_margin" menu="False" model="product.product" name="product.margin" string="Product Margin"/>
<wizard id="action_open_margin" menu="False" model="product.product" name="product.margins" string="Product Margins"/>
<menuitem id="menu_product_reporting" name="Reporting" parent ="product.menu_main_product" />
<menuitem icon="STOCK_JUSTIFY_FILL" action="action_open_margin" id="menu_action_product_margin" type="wizard" sequence="5" parent="menu_product_reporting" />
<record model="ir.ui.view" id="view_product_margin_graph">
<field name="name">product.margin.graph</field>
<field name="model">product.product</field>
<field name="type">graph</field>
<field name="arch" type="xml">
<graph string="Product Margins" type="bar">
<field name="name"/>
<field name="turnover" operator="+"/>
<field name="total_cost" operator="+"/>
</graph>
</field>
</record>
<record id="view_product_margin_form" model="ir.ui.view">
<field name="name">product.margin.form.inherit</field>
<field name="model">product.product</field>
<field name="type">form</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="priority">10</field>
<field name="arch" type="xml">
<page string="Prices" position="after">
<page string="Margin">
<field name="type">form</field>
<field name="priority">5</field>
<field name="arch" type="xml">
<form string="Product Margins">
<group col="6" colspan="4">
<field name="name" select="1"/>
<field name="default_code" select="1"/>
</group>
<notebook colspan="4">
<page string="Margins">
<separator string="Analysis Criteria" colspan="4"/>
<field name="date_from"/>
<field name="date_to"/>
@ -42,11 +59,12 @@
<separator string="Margins" colspan="4"/>
<field name="total_margin"/>
<field name="expected_margin"/>
<field name="total_margin_rate" widget="progressbar"/>
<field name="total_margin_rate" widget="progressbar"/>
<field name="expected_margin_rate" widget="progressbar"/>
</page>
</page>
</page>
</notebook>
</form>
</field>
</record>
@ -55,18 +73,19 @@
<field name="model">product.product</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Product Margin">
<tree string="Product Margins">
<field name="name" select="1"/>
<field name="default_code" select="1"/>
<field name="sale_avg_price"/>
<field name="sale_num_invoiced"/>
<field name="turnover"/>
<field name="sales_gap"/>
<field name="total_cost"/>
<field name="turnover" sum="Turnover"/>
<field name="sales_gap" sum="Sales Gap"/>
<field name="total_cost" sum="Total Cost"/>
<field name="purchase_num_invoiced" string="#Purchased"/>
<field name="total_margin"/>
<field name="expected_margin"/>
<field name="total_margin_rate" widget="progressbar"/>
<field name="expected_margin_rate" widget="progressbar"/>
</tree>
</field>
</record>

View File

@ -36,17 +36,17 @@ def _action_open_window(self, cr, uid, data, context):
cr.execute('select id,name from ir_ui_view where name=%s and type=%s', ('product.margin.tree', 'tree'))
view_res = cr.fetchone()
return {
'name': 'Product Margin',
'name': 'Product Margins',
'context':{'date_from':data['form']['from_date'],'date_to':data['form']['to_date'],'invoice_state' : data['form']['invoice_state']},
'view_type': 'form',
"view_mode": 'tree,form',
"view_mode": 'tree,form,graph',
'res_model':'product.product',
'type': 'ir.actions.act_window',
'view_id': view_res,
}
class product_margin(wizard.interface):
class product_margins(wizard.interface):
form1 = '''<?xml version="1.0"?>
<form string="View Stock of Products">
<separator string="Select " colspan="4"/>
@ -58,28 +58,32 @@ class product_margin(wizard.interface):
'from_date': {
'string': 'From',
'type': 'date',
'default': lambda *a:time.strftime('%Y-01-01'),
},
'to_date': {
'string': 'To',
'type': 'date',
'default': lambda *a:time.strftime('%Y-12-31'),
},
'invoice_state': {
'string': 'Invoice State',
'type': 'selection',
'selection': [('paid','Paid'),('open','All Open'),('draft_open','Draft and Open')],
'selection': [('paid','Paid'),('open_paid','Open and Paid'),('draft_open_paid','Draft, Open and Paid'),],
'required': True,
'default': lambda *a:"open",
'default': lambda *a:"open_paid",
},
}
states = {
'init': {
'actions': [],
'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, 'state': [('end', 'Cancel','gtk-cancel'),('open', 'Open Margin','gtk-ok')]}
'result': {'type': 'form', 'arch':form1, 'fields':form1_fields, 'state': [('end', 'Cancel','gtk-cancel'),('open', 'Open Margins','gtk-ok')]}
},
'open': {
'actions': [],
'result': {'type': 'action', 'action': _action_open_window, 'state':'end'}
}
}
product_margin('product.margin')
product_margins('product.margins')