mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-27 11:32:04 +02:00
Initial commit: Sale packages
This commit is contained in:
commit
14e3d26998
6469 changed files with 2479670 additions and 0 deletions
42
odoo-bringout-oca-ocb-sale_mrp/sale_mrp/models/mrp_bom.py
Normal file
42
odoo-bringout-oca-ocb-sale_mrp/sale_mrp/models/mrp_bom.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import _, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class MrpBom(models.Model):
|
||||
_inherit = 'mrp.bom'
|
||||
|
||||
def toggle_active(self):
|
||||
self.filtered(lambda bom: bom.active)._ensure_bom_is_free()
|
||||
return super().toggle_active()
|
||||
|
||||
def write(self, vals):
|
||||
if 'phantom' in self.mapped('type') and vals.get('type', 'phantom') != 'phantom':
|
||||
self._ensure_bom_is_free()
|
||||
return super().write(vals)
|
||||
|
||||
def unlink(self):
|
||||
self._ensure_bom_is_free()
|
||||
return super().unlink()
|
||||
|
||||
def _ensure_bom_is_free(self):
|
||||
product_ids = []
|
||||
for bom in self:
|
||||
if bom.type != 'phantom':
|
||||
continue
|
||||
product_ids += bom.product_id.ids or bom.product_tmpl_id.product_variant_ids.ids
|
||||
if not product_ids:
|
||||
return
|
||||
lines = self.env['sale.order.line'].sudo().search([
|
||||
('state', 'in', ('sale', 'done')),
|
||||
('invoice_status', 'in', ('no', 'to invoice')),
|
||||
('product_id', 'in', product_ids),
|
||||
('move_ids.state', '!=', 'cancel'),
|
||||
])
|
||||
if lines:
|
||||
product_names = ', '.join(lines.product_id.mapped('display_name'))
|
||||
raise UserError(_('As long as there are some sale order lines that must be delivered/invoiced and are '
|
||||
'related to these bills of materials, you can not remove them.\n'
|
||||
'The error concerns these products: %s', product_names))
|
||||
Loading…
Add table
Add a link
Reference in a new issue