update product_seq

add all default
This commit is contained in:
ivan deng
2017-12-19 02:58:53 +08:00
parent 67e59352f3
commit 39c09334a5
12 changed files with 542 additions and 70 deletions

View File

@@ -21,18 +21,42 @@ from openerp import api, fields, models, _
class ProductInternalType(models.Model):
_name = "product.internal.type"
name = fields.Char('Display Name',default='Normal')
name = fields.Char('Display Name', default='Normal', translate=True)
description = fields.Char('Description')
# 因为default_code有odoo的处理方式影响面大故会将其另存到 default_code_stored
ref = fields.Char('Unique Code', required=True)
link_sequence = fields.Many2one(
'ir.sequence', 'Link Sequence',
auto_join=True, required=True, domain="[('code', '=', 'product.product')]")
sequence_prefix = fields.Char(u'Sequence Prefix', related='link_sequence.prefix', readonly=True, store=False)
# 各种默认值,填则自动录入,不填则不管
type = fields.Selection([
('consu', _('Consumable')),
('service', _('Service')),
('product', _('Stockable Product'))], string='Product Type',
help='A stockable product is a product for which you manage stock. The "Inventory" app has to be installed.\n'
'A consumable product, on the other hand, is a product for which stock is not managed.\n'
'A service is a non-material product you provide.\n'
'A digital content is a non-material product you sell online. The files attached to the products are the one that are sold on '
'the e-commerce such as e-books, music, pictures,... The "Digital Product" module has to be installed.')
rental = fields.Boolean('Can be Rent')
sale_ok = fields.Boolean(
'Can be Sold', default=True,
help="Specify if the product can be selected in a sales order line.")
purchase_ok = fields.Boolean('Can be Purchased', default=True)
# 使用目录的默认路线来处理,暂时不用内部类型路线
route_ids = fields.Many2many('stock.location.route', string='Routes',
domain=[('product_selectable', '=', True)],
help="Depending on the modules installed, this will allow you to define the route of the product: whether it will be bought, manufactured, MTO/MTS,...")
# company_id = fields.Many2one(
# 'res.company', 'Company',
# default=lambda self: self.env.user.company_id.id, index=1)
# _sql_constraints = [
# ('uniq_link_sequence',
# 'unique(link_sequence)',
# 'The Link Sequence must be unique'),
# ]
_sql_constraints = [
('uniq_ref',
'unique(ref)',
'The reference must be unique'),
]

View File

@@ -73,7 +73,8 @@ class ProductProduct(models.Model):
else:
# create from product_product
sequence = self.env['product.internal.type'].search([('id', '=', vals['internal_type'])], limit=1)
vals['default_code'] = sequence.link_sequence.next_by_id()
if sequence:
vals['default_code'] = sequence.link_sequence.next_by_id()
return super(ProductProduct, self).create(vals)
@api.multi

View File

@@ -22,6 +22,7 @@ class ProductTemplate(models.Model):
_name = "product.template"
_inherit = ['product.template']
# auto_join只要搜索product.template自动会join。如果经常用到 internal_type 效率会高。
internal_type = fields.Many2one(
'product.internal.type', 'Internal Type',
auto_join=True, required=True)
@@ -58,6 +59,17 @@ class ProductTemplate(models.Model):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.default_code = self.default_code_stored
# 当内部类型变化时,改变产品模板的各默认值
@api.onchange('internal_type')
def _onchange_internal_type(self):
if self.internal_type:
self.type = self.internal_type.type
self.rental = self.internal_type.rental
self.sale_ok = self.internal_type.sale_ok
self.purchase_ok = self.internal_type.purchase_ok
self.route_ids = self.internal_type.route_ids
# 分类变动时,如果分类绑定了内部类型则联动
@api.onchange('categ_id')
def _onchange_cate_id(self):
if self.categ_id and self.categ_id.internal_type: