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
=== modified file 'project_mrp/project.py'
--- project_mrp/project.py 2009-01-04 22:12:50 +0000
+++ project_mrp/project.py 2010-06-24 09:43:24 +0000
@@ -47,5 +47,37 @@
47 wf_service.trg_validate(uid, 'mrp.procurement', task.procurement_id.id, 'subflow.cancel', cr)47 wf_service.trg_validate(uid, 'mrp.procurement', task.procurement_id.id, 'subflow.cancel', cr)
48 return True48 return True
49project_task()49project_task()
50
51# Override mrp.procurement with quantity computations
52class project_procurement(osv.osv):
53 _name = "mrp.procurement"
54 _inherit = "mrp.procurement"
55
56 def _quantity_compute_get(self, cr, uid, proc, context={}):
57 if proc.product_id.type=='service':
58 taskids = self.pool.get('project.task').search(cr, uid,
59 [('procurement_id', 'in', [proc.id])])
60 if taskids:
61 task = self.pool.get('project.task').browse(cr, uid,
62 taskids[0], context=context)
63 return task.total_hours
64 return super(project_procurement, self)._quantity_compute_get(self, cr,
65 uid, proc, context)
66project_procurement()
67
68# Override sales order with calculations for line price
69class sale_order_line(osv.osv):
70 _name = 'sale.order.line'
71 _inherit = 'sale.order.line'
72
73 def _get_invoice_line_price(self, cr, uid, line, uosqty, context={}):
74 if line.procurement_id:
75 if ((line.product_id.type=='service') and
76 (line.order_id.invoice_quantity=='procurement')):
77 return line.price_unit
78 return super(sale_order_line, self)._get_invoice_line_price(cr, uid,
79 line, uosqty, context)
80sale_order_line()
81
50# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:82# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
5183
5284
=== modified file 'sale/sale.py'
--- sale/sale.py 2010-06-02 15:05:51 +0000
+++ sale/sale.py 2010-06-24 09:43:24 +0000
@@ -786,6 +786,12 @@
786 'product_packaging': lambda *a: False786 'product_packaging': lambda *a: False
787 }787 }
788788
789 def _get_invoice_line_price(self, cr, uid, line, uosqty, context={}):
790 """Calculate and return the price for a invoice line based on quantity """
791 return round(line.price_unit * line.product_uom_qty / uosqty,
792 int(config['price_accuracy']))
793
794
789 def invoice_line_create(self, cr, uid, ids, context={}):795 def invoice_line_create(self, cr, uid, ids, context={}):
790 def _get_line_qty(line):796 def _get_line_qty(line):
791 if (line.order_id.invoice_quantity=='order') or not line.procurement_id:797 if (line.order_id.invoice_quantity=='order') or not line.procurement_id:
@@ -826,8 +832,8 @@
826 uos_id = _get_line_uom(line)832 uos_id = _get_line_uom(line)
827 pu = 0.0833 pu = 0.0
828 if uosqty:834 if uosqty:
829 pu = round(line.price_unit * line.product_uom_qty / uosqty,835 pu = self._get_invoice_line_price(cr, uid, line, uosqty,
830 int(config['price_accuracy']))836 context)
831 fpos = line.order_id.fiscal_position or False837 fpos = line.order_id.fiscal_position or False
832 a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, a)838 a = self.pool.get('account.fiscal.position').map_account(cr, uid, fpos, a)
833 if not a:839 if not a: