zoukankan      html  css  js  c++  java
  • openerp学习笔记 单据自动编号(编码规则)

    说明:

      单据自动编码允许定义 单据前缀+按当前年、月、日、时、分、秒+流水号+单据后缀
      单据自动编号允许按所有公司统一编号或按分公司单独编号
      单据自动编号中的流水号部分未按月重新编号,不断累计,当超出定义长度时,自动进位增加位数
      暂时未实现按月重新编号,需要每月手工在设置中改变下一编号(客户肯定不会同意这样做的,待解决)

    示例代码 xml 部分,编码规则定义:
    sale_sequence.xml

    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
        <data noupdate="1">
            <!-- Sequences for dispatch.sale --> 
            <record id="seq_type_dispatch_sale" model="ir.sequence.type">
                <field name="name">Dispatch Sale</field>
                <field name="code">dispatch.sale</field>
            </record>
            <record id="seq_dispatch_sale" model="ir.sequence">
                <field name="name">Dispatch Sale</field>
                <field name="code">dispatch.sale</field>
                <field name="prefix">po-%(y)s%(month)s-</field>
                <field name="padding">4</field>
                <field name="company_id" eval="False"/>
            </record>
        </data>
    </openerp>

     示例代码 python 部分:

        _columns={
            'name':fields.char(u'单号', size=64, select=True, required=True, readonly=True),
            'date':fields.date(u'日期', select=True, required=True, readonly=True),
            'month':fields.function(_get_month, method=True, type='char', size=10, string = u'月份', store=True, invisible=True),
            "customer":fields.many2one("dispatch.customer","客户", select=True, required=True, readonly=True, states={'draft':[('readonly',False)]}),
            "product":fields.many2one("dispatch.product","产品", select=True, required=True, readonly=True, states={'draft':[('readonly',False)]}),
            'price':fields.float(u'单价', digits=(18, 2), required=True, readonly=True, states={'draft':[('readonly',False)]}),
            'num':fields.integer(u'数量', required=True, readonly=True, states={'draft':[('readonly',False)]}),
            'cost':fields.float(u'成本', digits=(18, 2), required=True, invisible=False),
            'cost_view':fields.function(_view_cost, method=True, type='float', digits=(18, 2), string = u'成本', invisible=True),
            'sum_sale':fields.function(_sum_sale, method=True, type='float', digits=(18, 2), string = u'销售金额', store=True),
            'sum_cost':fields.function(_sum_cost, method=True, type='float', digits=(18, 2), string = u'成本金额', store=True),
            'sum_profit':fields.function(_sum_profit, method=True, type='float', digits=(18, 2), string = u'利润金额', store=True),
            'employee_id':fields.many2one('hr.employee',u'业务员', select=True, required=True, readonly=True, states={'draft':[('readonly',False)]}),
            'department_id':fields.many2one('hr.department',u'部门', select=True, required=True, readonly=True, states={'draft':[('readonly',False)]}),
            'klbh':fields.char(u'开龙单号',size=64,required=False, readonly=True, states={'draft':[('readonly',False)]}),
            "work_order":fields.many2one("dispatch.work_order","服务单", required=False, readonly=True, states={'draft':[('readonly',False)]}),
            'note':fields.text(u'备注', readonly=True, states={'draft':[('readonly',False)]}),
            'state': fields.selection([('draft', u'草稿'),('confirmed', u'已确认')], u'状态', select=True, readonly=True),
            'create_uid': fields.many2one('res.users', u"创建用户", select=True, invisible=False, readonly=True), #需要在记录中读取该字段或者在视图中显示该字段时,对象中必须包含
        }
        _defaults={
            'name': lambda obj, cr, uid, context: '/',
            'date':fields.date.context_today,
            #'employee_id':_employee_get,
            'state':'draft'
        }
       
        #数据库约束
        _sql_constraints = [
            ('name_check', "unique(name)", u"单据编号已经存在且不允许重复."),
            ('num_check', "CHECK (num <> 0 )", u"销售数量不能等于 0 ."),
        ]
       
        def create(self, cr, uid, vals, context=None):
            if vals.get('name','/')=='/':
                vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'dispatch.sale') or '/'
            return super(dispatch_sale, self).create(cr, uid, vals, context=context)

  • 相关阅读:
    投票协议:二进制表示方法
    投票协议:构建和解析协议消息
    多任务处理:多线程
    通信:成帧与解析
    通信:组合输入输出流
    跨越FSO WSH写文件
    MS07004漏洞
    解决ASP(图像)上传漏洞的方法
    让硬件入侵不再是神话
    解决ASP(图像)上传漏洞的方法
  • 原文地址:https://www.cnblogs.com/cnshen/p/3159179.html
Copyright © 2011-2022 走看看