Merge lp:~ressu/openobject-addons/project_mrp_invoicing into lp:openobject-addons/5.0

Proposed by Sami Haahtinen
Status: Needs review
Proposed branch: lp:~ressu/openobject-addons/project_mrp_invoicing
Merge into: lp:openobject-addons/5.0
Diff against target: 69 lines (+40/-2)
2 files modified
project_mrp/project.py (+32/-0)
sale/sale.py (+8/-2)
To merge this branch: bzr merge lp:~ressu/openobject-addons/project_mrp_invoicing
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+28380@code.launchpad.net

Description of the change

Add support for creating invoices based on service tasks generated from sales orders.

It modifies sale.order.line so that unit price calculations can be overridden and overrides quantity calculations from mrp module.

It can be tested by creating a sales order with a service. After completing the task and the project, the invoice will be generated based on the amount of work done with the task.

Price will be calculated based on the unit price of the sales order. Unlike with the default behaviour of mrp sales order, the total price can vary depending on the amount of hours put to the task.

To post a comment you must log in.

Unmerged revisions

2765. By Sami Haahtinen

Make invoices respect the work done in tasks when invoice is generated based on shipped items

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'project_mrp/project.py'
2--- project_mrp/project.py 2009-01-04 22:12:50 +0000
3+++ project_mrp/project.py 2010-06-24 09:43:24 +0000
4@@ -47,5 +47,37 @@
5 wf_service.trg_validate(uid, 'mrp.procurement', task.procurement_id.id, 'subflow.cancel', cr)
6 return True
7 project_task()
8+
9+# Override mrp.procurement with quantity computations
10+class project_procurement(osv.osv):
11+ _name = "mrp.procurement"
12+ _inherit = "mrp.procurement"
13+
14+ def _quantity_compute_get(self, cr, uid, proc, context={}):
15+ if proc.product_id.type=='service':
16+ taskids = self.pool.get('project.task').search(cr, uid,
17+ [('procurement_id', 'in', [proc.id])])
18+ if taskids:
19+ task = self.pool.get('project.task').browse(cr, uid,
20+ taskids[0], context=context)
21+ return task.total_hours
22+ return super(project_procurement, self)._quantity_compute_get(self, cr,
23+ uid, proc, context)
24+project_procurement()
25+
26+# Override sales order with calculations for line price
27+class sale_order_line(osv.osv):
28+ _name = 'sale.order.line'
29+ _inherit = 'sale.order.line'
30+
31+ def _get_invoice_line_price(self, cr, uid, line, uosqty, context={}):
32+ if line.procurement_id:
33+ if ((line.product_id.type=='service') and
34+ (line.order_id.invoice_quantity=='procurement')):
35+ return line.price_unit
36+ return super(sale_order_line, self)._get_invoice_line_price(cr, uid,
37+ line, uosqty, context)
38+sale_order_line()
39+
40 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
41
42
43=== modified file 'sale/sale.py'
44--- sale/sale.py 2010-06-02 15:05:51 +0000
45+++ sale/sale.py 2010-06-24 09:43:24 +0000
46@@ -786,6 +786,12 @@
47 'product_packaging': lambda *a: False
48 }
49
50+ def _get_invoice_line_price(self, cr, uid, line, uosqty, context={}):
51+ """Calculate and return the price for a invoice line based on quantity """
52+ return round(line.price_unit * line.product_uom_qty / uosqty,
53+ int(config['price_accuracy']))
54+
55+
56 def invoice_line_create(self, cr, uid, ids, context={}):
57 def _get_line_qty(line):
58 if (line.order_id.invoice_quantity=='order') or not line.procurement_id:
59@@ -826,8 +832,8 @@
60 uos_id = _get_line_uom(line)
61 pu = 0.0
62 if uosqty:
63- pu = round(line.price_unit * line.product_uom_qty / uosqty,
64- int(config['price_accuracy']))
65+ pu = self._get_invoice_line_price(cr, uid, line, uosqty,
66+ context)
67 fpos = line.order_id.fiscal_position or False
68 a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, a)
69 if not a: