|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Copyright 2017 Eficent Business and IT Consulting Services S.L. |
| 3 | +# (http://www.eficent.com) |
| 4 | +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
| 5 | + |
| 6 | +from openerp import api, fields, models |
| 7 | +import openerp.addons.decimal_precision as dp |
| 8 | + |
| 9 | + |
| 10 | +class PurchaseOrderLine(models.Model): |
| 11 | + _inherit = 'purchase.order.line' |
| 12 | + |
| 13 | + @api.depends('product_qty', 'qty_invoiced') |
| 14 | + def _compute_qty_to_invoice(self): |
| 15 | + for line in self: |
| 16 | + line.qty_to_invoice = line.product_qty - line.qty_invoiced |
| 17 | + |
| 18 | + @api.depends('order_id.state', 'move_ids.state', 'product_qty') |
| 19 | + def _compute_qty_received(self): |
| 20 | + super(PurchaseOrderLine, self)._compute_qty_received() |
| 21 | + for line in self: |
| 22 | + line.qty_to_receive = line.product_qty - line.qty_received |
| 23 | + |
| 24 | + qty_to_invoice = fields.Float(compute='_compute_qty_to_invoice', |
| 25 | + digits=dp.get_precision( |
| 26 | + 'Product Unit of Measure'), |
| 27 | + copy=False, |
| 28 | + string="Qty to Bill", store=True) |
| 29 | + qty_to_receive = fields.Float(compute='_compute_qty_received', |
| 30 | + digits=dp.get_precision( |
| 31 | + 'Product Unit of Measure'), |
| 32 | + copy=False, |
| 33 | + string="Qty to Receive", store=True) |
| 34 | + |
| 35 | + |
| 36 | +class PurchaseOrder(models.Model): |
| 37 | + _inherit = 'purchase.order' |
| 38 | + |
| 39 | + def _compute_qty_to_invoice(self): |
| 40 | + for po in self: |
| 41 | + po.qty_to_invoice = sum(po.mapped('order_line.qty_to_invoice')) |
| 42 | + |
| 43 | + def _compute_qty_to_receive(self): |
| 44 | + for po in self: |
| 45 | + po.qty_to_receive = sum(po.mapped('order_line.qty_to_receive')) |
| 46 | + |
| 47 | + @api.model |
| 48 | + def _search_qty_to_invoice(self, operator, value): |
| 49 | + po_line_obj = self.env['purchase.order.line'] |
| 50 | + res = [] |
| 51 | + po_lines = po_line_obj.search( |
| 52 | + [('qty_to_invoice', operator, value)]) |
| 53 | + order_ids = po_lines.mapped('order_id') |
| 54 | + res.append(('id', 'in', order_ids.ids)) |
| 55 | + return res |
| 56 | + |
| 57 | + @api.model |
| 58 | + def _search_qty_to_receive(self, operator, value): |
| 59 | + po_line_obj = self.env['purchase.order.line'] |
| 60 | + res = [] |
| 61 | + po_lines = po_line_obj.search( |
| 62 | + [('qty_to_receive', operator, value)]) |
| 63 | + order_ids = po_lines.mapped('order_id') |
| 64 | + res.append(('id', 'in', order_ids.ids)) |
| 65 | + return res |
| 66 | + |
| 67 | + qty_to_invoice = fields.Float(compute='_compute_qty_to_invoice', |
| 68 | + search='_search_qty_to_invoice', |
| 69 | + string="Qty to Bill", |
| 70 | + default=0.0) |
| 71 | + qty_to_receive = fields.Float(compute='_compute_qty_to_receive', |
| 72 | + search='_search_qty_to_receive', |
| 73 | + string="Qty to Receive", |
| 74 | + default=0.0) |
0 commit comments