mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
###############################################################################
|
|
#
|
|
# Module for OpenERP
|
|
# Copyright (C) 2015 Akretion (http://www.akretion.com).
|
|
# @author Sébastien BEAU <sebastien.beau@akretion.com>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
###############################################################################
|
|
|
|
from openerp import models, fields, api
|
|
from collections import defaultdict
|
|
from openerp.exceptions import Warning as UserError
|
|
|
|
|
|
class ProductTemplate(models.Model):
|
|
_inherit = 'product.template'
|
|
|
|
bom_line_ids = fields.One2many(
|
|
'mrp.bom.line',
|
|
'product_tmpl_id',
|
|
string='Bom Line',
|
|
help='If you product is manufactured you can select'
|
|
'here the componant to product them')
|
|
|
|
@api.model
|
|
def _extract_bom_line(self, vals):
|
|
return vals.pop('bom_line_ids', {})
|
|
|
|
@api.multi
|
|
def _prepare_bom_vals(self, vals):
|
|
return {
|
|
'product_tmpl_id': self.id,
|
|
'bom_line_ids': vals,
|
|
}
|
|
|
|
@api.one
|
|
def _process_bom_vals(self, vals):
|
|
if self.bom_ids:
|
|
self.bom_ids[0].write({'bom_line_ids': vals})
|
|
else:
|
|
bom = self.env['mrp.bom'].create(self._prepare_bom_vals(vals))
|
|
|
|
@api.model
|
|
def create(self, vals):
|
|
bom_vals = self._extract_bom_line(vals)
|
|
record = super(ProductTemplate, self).create(vals)
|
|
if bom_vals:
|
|
record._process_bom_vals(bom_vals)
|
|
return record
|
|
|
|
@api.multi
|
|
def write(self, vals):
|
|
bom_vals = self._extract_bom_line(vals)
|
|
res = super(ProductTemplate, self).write(vals)
|
|
if bom_vals:
|
|
self._process_bom_vals(bom_vals)
|
|
return res
|
|
|
|
@api.multi
|
|
def unlink(self):
|
|
for record in self:
|
|
if record.bom_ids:
|
|
record.bom_ids.unlink()
|
|
return super(ProductTemplate, self).unlink()
|