|
|
@ -30,7 +30,8 @@ class ProductPack(models.Model): |
|
|
|
|
|
|
|
def default_pack_location(self): |
|
|
|
company_user = self.env.company |
|
|
|
warehouse = self.env['stock.warehouse'].search([('company_id', '=', company_user.id)], limit = 1) |
|
|
|
warehouse = self.env['stock.warehouse'].search([( |
|
|
|
'company_id', '=', company_user.id)], limit=1) |
|
|
|
if warehouse: |
|
|
|
return warehouse.lot_stock_id.id |
|
|
|
|
|
|
@ -62,15 +63,16 @@ class ProductPack(models.Model): |
|
|
|
|
|
|
|
def write(self, values): |
|
|
|
super(ProductPack, self).write(values) |
|
|
|
if self.is_pack: |
|
|
|
if not self.pack_products_ids: |
|
|
|
raise UserError(_( |
|
|
|
'You need to add atleast one product in the Pack...!')) |
|
|
|
if self.type == 'service': |
|
|
|
raise UserError(_('You cannot define a pack product as a service..!')) |
|
|
|
for rec in self: |
|
|
|
if rec.is_pack: |
|
|
|
if not rec.pack_products_ids: |
|
|
|
raise UserError(_( |
|
|
|
'You need to add atleast one product in the Pack...!')) |
|
|
|
if rec.type == 'service': |
|
|
|
raise UserError(_('You cannot define a pack product as a service..!')) |
|
|
|
|
|
|
|
def update_price_product(self): |
|
|
|
self.lst_price = self.pack_price |
|
|
|
self.list_price = self.pack_price |
|
|
|
|
|
|
|
def get_quantity(self): |
|
|
|
total_quantity = 1 |
|
|
@ -93,7 +95,8 @@ class ProductPack(models.Model): |
|
|
|
product_id = len(self.product_variant_ids) == 1 and self.product_variant_id.id |
|
|
|
location_id = self.pack_location_id.id |
|
|
|
if not location_id: |
|
|
|
warehouse = self.env['stock.warehouse'].search([('company_id', '=', company_user.id)], limit = 1) |
|
|
|
warehouse = self.env['stock.warehouse'].search([( |
|
|
|
'company_id', '=', company_user.id)], limit = 1) |
|
|
|
location_id = warehouse.lot_stock_id.id |
|
|
|
if not location_id: |
|
|
|
raise UserError(_( |
|
|
@ -108,9 +111,10 @@ class ProductPack(models.Model): |
|
|
|
def change_quantity_based_on_location(self): |
|
|
|
for line in self.pack_products_ids: |
|
|
|
stock_quant = self.env['stock.quant'].search( |
|
|
|
[('product_id', '=', line.product_id.id), ('location_id', '=', self.pack_location_id.id)]) |
|
|
|
[('product_id', '=', line.product_id.id), ( |
|
|
|
'location_id', '=', self.pack_location_id.id)]) |
|
|
|
if stock_quant: |
|
|
|
line.total_available_quantity = stock_quant.quantity |
|
|
|
|
|
|
|
else: |
|
|
|
line.total_available_quantity = stock_quant.quantity |
|
|
|
line.total_available_quantity = stock_quant.quantity |
|
|
|