pack.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. # For copyright and license notices, see __openerp__.py file in root directory
  4. ##############################################################################
  5. from openerp import fields, models, api
  6. import openerp.addons.decimal_precision as dp
  7. class product_pack(models.Model):
  8. _name = 'product.pack.line'
  9. _rec_name = 'product_id'
  10. parent_product_id = fields.Many2one(
  11. 'product.product',
  12. 'Parent Product',
  13. ondelete='cascade',
  14. required=True
  15. )
  16. quantity = fields.Float(
  17. 'Quantity',
  18. required=True,
  19. default=1.0,
  20. digits=dp.get_precision('Product UoS'),
  21. )
  22. product_id = fields.Many2one(
  23. 'product.product',
  24. 'Product',
  25. ondelete='cascade',
  26. required=True,
  27. )
  28. discount = fields.Float(
  29. 'Discount (%)',
  30. digits=dp.get_precision('Discount'),
  31. )
  32. price = fields.Float(
  33. 'Precio',
  34. required=True,
  35. default=0.0,
  36. )
  37. subtotal = fields.Float(
  38. 'Subtotal',
  39. required=True,
  40. compute="_product_price_subtotal"
  41. )
  42. # @api.onchange('product_id')
  43. # def get_price(self):
  44. # self.price = self.product_id.lst_price
  45. # self.subtotal = self.price * self.quantity
  46. # @api.onchange('quantity')
  47. # def get_subtotal(self):
  48. # self.subtotal = self.price * self.quantity
  49. @api.one
  50. @api.depends('product_id')
  51. def _product_price_subtotal(self):
  52. self.price = self.product_id.lst_price
  53. self.subtotal = self.price * self.quantity
  54. @api.multi
  55. def get_sale_order_line_vals(self, line, order):
  56. self.ensure_one()
  57. # pack_price = 0.0
  58. subproduct = self.product_id
  59. quantity = self.quantity * line.product_uom_qty
  60. taxes = order.fiscal_position.map_tax(
  61. subproduct.taxes_id)
  62. tax_id = [(6, 0, taxes.ids)]
  63. if subproduct.uos_id:
  64. uos_id = subproduct.uos_id.id
  65. uos_qty = quantity * subproduct.uos_coeff
  66. else:
  67. uos_id = False
  68. uos_qty = quantity
  69. # if pack is fixed price or totlice price we don want amount on
  70. # pack lines
  71. if line.product_id.pack_price_type in [
  72. 'fixed_price', 'totalice_price']:
  73. price = 0.0
  74. discount = 0.0
  75. else:
  76. pricelist = order.pricelist_id.id
  77. price = self.env['product.pricelist'].price_get(
  78. subproduct.id, quantity,
  79. order.partner_id.id, context={
  80. 'uom': subproduct.uom_id.id,
  81. 'date': order.date_order})[pricelist]
  82. discount = self.discount
  83. # Obtain product name in partner's language
  84. if order.partner_id.lang:
  85. subproduct = subproduct.with_context(
  86. lang=order.partner_id.lang)
  87. subproduct_name = subproduct.name
  88. vals = {
  89. 'order_id': order.id,
  90. 'name': '%s%s' % (
  91. '> ' * (line.pack_depth + 1), subproduct_name
  92. ),
  93. # 'delay': subproduct.sale_delay or 0.0,
  94. 'product_id': subproduct.id,
  95. # 'procurement_ids': (
  96. # [(4, x.id) for x in line.procurement_ids]
  97. # ),
  98. 'price_unit': price,
  99. 'tax_id': tax_id,
  100. 'address_allotment_id': False,
  101. 'product_uom_qty': quantity,
  102. 'product_uom': subproduct.uom_id.id,
  103. 'product_uos_qty': uos_qty,
  104. 'product_uos': uos_id,
  105. 'product_packaging': False,
  106. 'discount': discount,
  107. 'number_packages': False,
  108. 'th_weight': False,
  109. 'state': 'draft',
  110. 'pack_parent_line_id': line.id,
  111. 'pack_depth': line.pack_depth + 1,
  112. }
  113. return vals
  114. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: