123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- # -*- encoding: utf-8 -*-
- ##############################################################################
- # For copyright and license notices, see __openerp__.py file in root directory
- ##############################################################################
- from openerp import fields, models, api
- import openerp.addons.decimal_precision as dp
- class product_pack(models.Model):
- _name = 'product.pack.line'
- _rec_name = 'product_id'
- parent_product_id = fields.Many2one(
- 'product.product',
- 'Parent Product',
- ondelete='cascade',
- required=True
- )
- quantity = fields.Float(
- 'Quantity',
- required=True,
- default=1.0,
- digits=dp.get_precision('Product UoS'),
- )
- product_id = fields.Many2one(
- 'product.product',
- 'Product',
- ondelete='cascade',
- required=True,
- )
- discount = fields.Float(
- 'Discount (%)',
- digits=dp.get_precision('Discount'),
- )
- price = fields.Float(
- 'Precio',
- required=True,
- default=0.0,
- )
- subtotal = fields.Float(
- 'Subtotal',
- required=True,
- compute="_product_price_subtotal"
- )
- @api.one
- @api.depends('product_id')
- def _product_price_subtotal(self):
- if(self.price > 0):
- self.subtotal = self.price * self.quantity
- else:
- self.price = self.product_id.lst_price
- self.subtotal = self.price * self.quantity
- @api.onchange('price')
- def _product_change_price_subtotal(self):
- if(self.price > 0):
- self.subtotal = self.price * self.quantity
- else:
- self.price = self.product_id.lst_price
- self.subtotal = self.price * self.quantity
- @api.onchange('quantity')
- def _product_change_quantity_subtotal(self):
- if(self.price > 0):
- self.subtotal = self.price * self.quantity
- else:
- self.price = self.product_id.lst_price
- self.subtotal = self.price * self.quantity
- @api.multi
- def get_sale_order_line_vals(self, line, order):
- self.ensure_one()
- # pack_price = 0.0
- subproduct = self.product_id
- quantity = self.quantity * line.product_uom_qty
- taxes = order.fiscal_position.map_tax(
- subproduct.taxes_id)
- tax_id = [(6, 0, taxes.ids)]
- if subproduct.uos_id:
- uos_id = subproduct.uos_id.id
- uos_qty = quantity * subproduct.uos_coeff
- else:
- uos_id = False
- uos_qty = quantity
- # if pack is fixed price or totlice price we don want amount on
- # pack lines
- if line.product_id.pack_price_type in [
- 'fixed_price', 'totalice_price']:
- price = 0.0
- discount = 0.0
- else:
- pricelist = order.pricelist_id.id
- price = self.env['product.pricelist'].price_get(
- subproduct.id, quantity,
- order.partner_id.id, context={
- 'uom': subproduct.uom_id.id,
- 'date': order.date_order})[pricelist]
- discount = self.discount
- # Obtain product name in partner's language
- if order.partner_id.lang:
- subproduct = subproduct.with_context(
- lang=order.partner_id.lang)
- subproduct_name = subproduct.name
- vals = {
- 'order_id': order.id,
- 'name': '%s%s' % (
- '> ' * (line.pack_depth + 1), subproduct_name
- ),
- # 'delay': subproduct.sale_delay or 0.0,
- 'product_id': subproduct.id,
- # 'procurement_ids': (
- # [(4, x.id) for x in line.procurement_ids]
- # ),
- 'price_unit': price,
- 'tax_id': tax_id,
- 'address_allotment_id': False,
- 'product_uom_qty': quantity,
- 'product_uom': subproduct.uom_id.id,
- 'product_uos_qty': uos_qty,
- 'product_uos': uos_id,
- 'product_packaging': False,
- 'discount': discount,
- 'number_packages': False,
- 'th_weight': False,
- 'state': 'draft',
- 'pack_parent_line_id': line.id,
- 'pack_depth': line.pack_depth + 1,
- }
- return vals
- # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|