[IMP] mrp_bom_reference_selection

* README updated
* onchange fixed
* code cleaned
* .pot deleted
This commit is contained in:
oihane
2015-12-09 16:55:02 +01:00
parent 5ddcbde68d
commit aa409a04d2
9 changed files with 87 additions and 232 deletions

View File

@@ -1,26 +1,8 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Savoir-faire Linux
# (<http://www.savoirfairelinux.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/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# (c) 2015 Savoir-faire Linux - <http://www.savoirfairelinux.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp import models, fields, api
from openerp import api, fields, models
class MrpBillOfMaterial(models.Model):
@@ -34,4 +16,5 @@ class MrpBillOfMaterial(models.Model):
return res
reference_id = fields.One2many(
'mrp.bom.reference', 'bom_id', string="BoM Reference")
comodel_name='mrp.bom.reference', inverse_name='bom_id',
string="BoM Reference")

View File

@@ -1,32 +1,15 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Savoir-faire Linux
# (<http://www.savoirfairelinux.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/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# (c) 2015 Savoir-faire Linux - <http://www.savoirfairelinux.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp import models, fields, api
from openerp import api, exceptions, fields, models, _
class MrpBillOfMaterialLine(models.Model):
_inherit = 'mrp.bom.line'
reference_id = fields.Many2one('mrp.bom.reference', 'Ref')
reference_id = fields.Many2one(
comodel_name='mrp.bom.reference', string='Ref')
product_tmpl_id = fields.Many2one(
'product.template', 'Product Template',
related='product_id.product_tmpl_id', store=True)
@@ -34,20 +17,35 @@ class MrpBillOfMaterialLine(models.Model):
product_id = fields.Many2one(
'product.product', required=True, string='Product')
@api.constrains('reference_id')
def _check_reference_id(self):
if (self.reference_id and
(self.reference_id.bom_id.product_tmpl_id !=
self.product_id.product_tmpl_id)):
raise exceptions.Warning(
_('Product %s from %s reference BoM must be equal to product'
' %s in BoM line.' %
(self.reference_id.bom_id.product_tmpl_id.name,
self.reference_id.name,
self.product_id.product_tmpl_id.name)))
@api.multi
def onchange_product_id(self, product_id, product_qty=0):
product = self.env['product.product'].browse(product_id)
res = super(MrpBillOfMaterialLine, self).onchange_product_id(
product_id, product_qty=product_qty)
if not product:
res['value']['reference_id'] = False
else:
if 'value' not in res:
res['value'] = {}
if 'domain' not in res:
res['domain'] = {}
if product_id:
product = self.env['product.product'].browse(product_id)
refs = self.env['mrp.bom.reference'].search(
[('bom_id.product_tmpl_id', '=', product.product_tmpl_id.id)])
res['value']['reference_id'] = refs and refs[0]
res['value']['reference_id'] = refs[:1]
res['domain']['reference_id'] = [('id', 'in', refs.ids)]
else:
res['value']['reference_id'] = False
res['domain']['reference_id'] = False
return res
@api.depends('product_id')

View File

@@ -1,34 +1,15 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Savoir-faire Linux
# (<http://www.savoirfairelinux.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/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# (c) 2015 Savoir-faire Linux - <http://www.savoirfairelinux.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp import models, fields
from openerp import fields, models
class MrpBillOfMaterialReference(models.Model):
_name = 'mrp.bom.reference'
_description = 'MRP Bill of Material Reference'
bom_id = fields.Many2one(
'mrp.bom', required=True, ondelete='cascade',
comodel_name='mrp.bom', required=True, ondelete='cascade',
string='Bill of Material')
name = fields.Char(related='bom_id.code', store=True)

View File

@@ -1,29 +1,8 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Savoir-faire Linux
# (<http://www.savoirfairelinux.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/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# (c) 2015 Savoir-faire Linux - <http://www.savoirfairelinux.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
import logging
from openerp import models, api
_logger = logging.getLogger(__name__)
from openerp import api, models
class MrpProduction(models.Model):
@@ -37,11 +16,7 @@ class MrpProduction(models.Model):
"""
res = super(MrpProduction, self).action_produce(
production_id, production_qty, production_mode, wiz)
production = self.browse(production_id)
for move in production.move_created_ids2:
prod_lots = move.lot_ids
prod_lots.write({'bom_id': production.bom_id.id})
prod_lots = production.mapped('move_created_ids2.lot_ids')
prod_lots.write({'bom_id': production.bom_id.id})
return res

View File

@@ -1,29 +1,12 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2015 Savoir-faire Linux
# (<http://www.savoirfairelinux.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/>.
#
##############################################################################
# -*- coding: utf-8 -*-
# (c) 2015 Savoir-faire Linux - <http://www.savoirfairelinux.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from openerp import models, fields
from openerp import fields, models
class StockProductionLot(models.Model):
_inherit = 'stock.production.lot'
bom_id = fields.Many2one('mrp.bom', 'Bill of Material')
bom_id = fields.Many2one(
comodel_name='mrp.bom', string='Bill of Material')