pack.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. @api.multi
  33. def get_sale_order_line_vals(self, line, order):
  34. self.ensure_one()
  35. # pack_price = 0.0
  36. subproduct = self.product_id
  37. quantity = self.quantity * line.product_uom_qty
  38. taxes = order.fiscal_position.map_tax(
  39. subproduct.taxes_id)
  40. tax_id = [(6, 0, taxes.ids)]
  41. if subproduct.uos_id:
  42. uos_id = subproduct.uos_id.id
  43. uos_qty = quantity * subproduct.uos_coeff
  44. else:
  45. uos_id = False
  46. uos_qty = quantity
  47. # if pack is fixed price or totlice price we don want amount on
  48. # pack lines
  49. if line.product_id.pack_price_type in [
  50. 'fixed_price', 'totalice_price']:
  51. price = 0.0
  52. discount = 0.0
  53. else:
  54. pricelist = order.pricelist_id.id
  55. price = self.env['product.pricelist'].price_get(
  56. subproduct.id, quantity,
  57. order.partner_id.id, context={
  58. 'uom': subproduct.uom_id.id,
  59. 'date': order.date_order})[pricelist]
  60. discount = self.discount
  61. # Obtain product name in partner's language
  62. if order.partner_id.lang:
  63. subproduct = subproduct.with_context(
  64. lang=order.partner_id.lang)
  65. subproduct_name = subproduct.name
  66. vals = {
  67. 'order_id': order.id,
  68. 'name': '%s%s' % (
  69. '> ' * (line.pack_depth + 1), subproduct_name
  70. ),
  71. # 'delay': subproduct.sale_delay or 0.0,
  72. 'product_id': subproduct.id,
  73. # 'procurement_ids': (
  74. # [(4, x.id) for x in line.procurement_ids]
  75. # ),
  76. 'price_unit': price,
  77. 'tax_id': tax_id,
  78. 'address_allotment_id': False,
  79. 'product_uom_qty': quantity,
  80. 'product_uom': subproduct.uom_id.id,
  81. 'product_uos_qty': uos_qty,
  82. 'product_uos': uos_id,
  83. 'product_packaging': False,
  84. 'discount': discount,
  85. 'number_packages': False,
  86. 'th_weight': False,
  87. 'state': 'draft',
  88. 'pack_parent_line_id': line.id,
  89. 'pack_depth': line.pack_depth + 1,
  90. }
  91. return vals
  92. # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: