purchase.py 984 B

1234567891011121314151617181920212223242526
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. from openerp import tools, api
  4. from openerp import api, fields, models, _
  5. # class PickingTotalQty(models.Model):
  6. # _inherit = 'purchase.order'
  7. #
  8. # tot_purchase_qty = fields.Float(compute='_calculate_purchase_qty', string='Total Cantidad Comprado', help="Total cantidad comprado")
  9. #
  10. # def _calculate_purchase_qty(self):
  11. # for rs in self:
  12. # sumqty = 0
  13. # for line in rs.order_line:
  14. # sumqty += line.product_qty
  15. # rs.tot_purchase_qty = sumqty
  16. class PurchaseOrder(models.Model):
  17. _inherit = 'purchase.order'
  18. tot_purchase_qty = fields.Float(string='Cantidad de Productos de Compra', compute='_calculate_purchase_qty')
  19. @api.depends('order_line.product_qty')
  20. def _calculate_purchase_qty(self):
  21. for order in self:
  22. order.tot_purchase_qty = sum(order.order_line.mapped('product_qty'))