123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- # -*- coding: utf-8 -*-
- ##############################################################################
- #
- # OpenERP, Open Source Management Solution
- # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
- #
- # 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
- class product_template(models.Model):
- _name = 'product.template'
- _inherit = 'product.template'
- factory_barcode = fields.Char('Código de barra de fábrica',size=64)
- factory_reference = fields.Char('Referencia de fábrica',size=64)
- _defaults = {
- 'type':'product',
- }
- @api.multi
- def write(self, vals):
- prod_tmpl_id = super(product_template,self).write(vals)
- for p in self.product_variant_ids:
- prod = self.env['product.product'].browse(p['id'])
- ref = ''
- if prod.factory_reference:
- if prod['factory_reference'] != None:
- #prod.factory_reference = prod['factory_reference']
- prod.factory_reference = self.factory_reference
- ref = prod['factory_reference']
- elif self.factory_reference:
- prod.factory_reference = self.factory_reference
- ref = self['factory_reference']
- if prod.factory_barcode:
- if prod['factory_barcode'] != None:
- prod.factory_barcode = prod['factory_barcode']
- ref = prod['factory_barcode']
- elif self.factory_barcode:
- prod.factory_barcode = self.factory_barcode
- ref = self['factory_barcode']
- prod['default_code'] = ref
- return prod_tmpl_id
- class product_product(models.Model):
- _name = 'product.product'
- _inherit = 'product.product'
- factory_barcode = fields.Char('Código de barra de fábrica',size=64)
- factory_reference = fields.Char('Referencia de fábrica',size=64)
- @api.model
- def create(self, vals):
- prod_id = super(product_product,self).create(vals)
- self.copiar_referencia(prod_id)
- return prod_id
- @api.model
- def copiar_referencia(self,prod_id):
- # print prod_id['id']
- prod_tmpl = self.env['product.template'].browse(prod_id['product_tmpl_id']['id'])
- #print prod_tmpl
- ref = ''
- if prod_tmpl.factory_reference:
- prod_id['factory_reference'] = prod_tmpl.factory_reference
- ref = prod_tmpl.factory_reference
- if prod_tmpl.factory_barcode:
- prod_id['factory_barcode'] = prod_tmpl.factory_barcode
- ref = prod_tmpl.factory_barcode
- prod_id['default_code'] = ref
- return True
- @api.onchange('factory_barcode')
- def copiar_referencia_codigo_barra(self):
- self.default_code = self.factory_barcode
- product_product()
|