<commit_before># -*- coding: utf-8 -*-
import odoo.addons.decimal_precision as dp
from odoo import api, fields, models, _
from odoo.exceptions import UserError


class goods(models.Model):
    _name = 'goods'

    @api.model
    def _get_default_not_saleable_impl(self):
        return False

    @api.model
    def _get_default_not_saleable(self):
        return self._get_default_not_saleable_impl()

    @api.multi
    def name_get(self):
        '''在many2one字段里显示 编号_名称'''
        res = []

        for goods in self:
            res.append((goods.id, goods.code and (
                goods.code + '_' + goods.name) or goods.name))
        return res

    @api.model
    def name_search(self, name='', args=None, operator='ilike', limit=100):
        '''在many2one字段中支持按编号搜索'''
        args = args or []
        if name:
            goods_ids = self.search([('code', 'ilike', name)])
            if goods_ids:
                return goods_ids.name_get()
        return super(goods, self).name_search(name=name, args=args,
                                              operator=operator, limit=limit)

    @api.model
    def create(self, vals):
        '''导入产品时，如果辅助单位为空，则用计量单位来填充它'''
        if not vals.get('uos_id'):
            vals.update({'uos_id': vals.get('uom_id')})
        return super(goods, self).create(vals)

    @api.multi
    def copy(self, default=None):
        if default is None:
            default = {}
        default.update(name=_('%s (copy)') % (self.name))
        return super(goods, self).copy(default=default)

    code = fields.Char(u'编号')
    name = fields.Char(u'名称', required=True, copy=False)
    category_id = fields.Many2one('core.category', u'产品类别',
                                  ondelete='restrict',
                                  domain=[('type', '=', 'goods')],
                                  context={'type': 'goods'}, required=True)
    uom_id = fields.Many2one('uom', ondelete='restrict',
                             string=u'计量单位', required=True)
    uos_id = fields.Many2one('uom', ondelete='restrict', string=u'辅助单位')
    conversion = fields.Float(
        string=u'转化率', default=1, digits=(16, 3), 
        help=u'1个辅助单位等于多少计量单位的数量，如1箱30个苹果，这里就输入30')
    cost = fields.Float(u'成本',
                        required=True,
                        digits=dp.get_precision('Amount'))
    tax_rate = fields.Float(u'税率(%)',
                            help=u'产品税率')
    not_saleable = fields.Boolean(u'不可销售',
                                  default=_get_default_not_saleable,
                                  help=u'商品是否不可销售，勾选了就不可销售，未勾选可销售')

    _sql_constraints = [
        ('name_uniq', 'unique(name)', '产品不能重名'),
        ('conversion_no_zero', 'check(conversion != 0)', '产品的转化率不能为0')
    ]


<commit_msg>[IMP] 产品名称复制的时候加“副本”，有面加判定条件，以扩展<commit_after># -*- coding: utf-8 -*-
import odoo.addons.decimal_precision as dp
from odoo import api, fields, models, _
from odoo.exceptions import UserError


class goods(models.Model):
    _name = 'goods'

    @api.model
    def _get_default_not_saleable_impl(self):
        return False

    @api.model
    def _get_default_not_saleable(self):
        return self._get_default_not_saleable_impl()

    @api.multi
    def name_get(self):
        '''在many2one字段里显示 编号_名称'''
        res = []

        for goods in self:
            res.append((goods.id, goods.code and (
                goods.code + '_' + goods.name) or goods.name))
        return res

    @api.model
    def name_search(self, name='', args=None, operator='ilike', limit=100):
        '''在many2one字段中支持按编号搜索'''
        args = args or []
        if name:
            goods_ids = self.search([('code', 'ilike', name)])
            if goods_ids:
                return goods_ids.name_get()
        return super(goods, self).name_search(name=name, args=args,
                                              operator=operator, limit=limit)

    @api.model
    def create(self, vals):
        '''导入产品时，如果辅助单位为空，则用计量单位来填充它'''
        if not vals.get('uos_id'):
            vals.update({'uos_id': vals.get('uom_id')})
        return super(goods, self).create(vals)

    @api.multi
    def copy(self, default=None):
        if default is None:
            default = {}
        if not default.has_key('name'):
            default.update(name=_('%s (copy)') % (self.name))
        return super(goods, self).copy(default=default)

    code = fields.Char(u'编号')
    name = fields.Char(u'名称', required=True, copy=False)
    category_id = fields.Many2one('core.category', u'产品类别',
                                  ondelete='restrict',
                                  domain=[('type', '=', 'goods')],
                                  context={'type': 'goods'}, required=True)
    uom_id = fields.Many2one('uom', ondelete='restrict',
                             string=u'计量单位', required=True)
    uos_id = fields.Many2one('uom', ondelete='restrict', string=u'辅助单位')
    conversion = fields.Float(
        string=u'转化率', default=1, digits=(16, 3), 
        help=u'1个辅助单位等于多少计量单位的数量，如1箱30个苹果，这里就输入30')
    cost = fields.Float(u'成本',
                        required=True,
                        digits=dp.get_precision('Amount'))
    tax_rate = fields.Float(u'税率(%)',
                            help=u'产品税率')
    not_saleable = fields.Boolean(u'不可销售',
                                  default=_get_default_not_saleable,
                                  help=u'商品是否不可销售，勾选了就不可销售，未勾选可销售')

    _sql_constraints = [
        ('name_uniq', 'unique(name)', '产品不能重名'),
        ('conversion_no_zero', 'check(conversion != 0)', '产品的转化率不能为0')
    ]



{'fraction_non_alphanumeric': 0.13721636591030908, 'fraction_numerical': 0.007504020010720028, 'mean_word_length': 2.042391304347826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4698079', 'n_tokens_mistral': 2020, 'n_tokens_neox': 2043, 'n_words': 314}