odoo 为单据创建自动编号ir_sequence_data
程序员文章站
2022-04-27 17:29:24
...
创建 data/ir_sequence_data.xml 并在__manifest__.py文件中引用
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record id="seq_sps_order" model="ir.sequence">
<field name="name">Sps Order</field>
<field name="code">sps.order.sequence</field>
<field name="prefix">%(year)s%(month)s%(day)s%(h24)s%(min)s%(sec)s</field>
</record>
</data>
</odoo>
重写create方法
@api.model
def create(self, vals):
vals['name'] = self.env['ir.sequence'].next_by_code('sps.order.sequence') or '/'
print(vals['name'])
res = super(SpsOrder, self).create(vals)
return res
关于 %( xxx )s :
图例(前缀,后缀)
年代: %(year)s | |
年份: %(y)s | |
月: %(month)s | |
日: %(day)s |
当年第几天: %(doy)s | |
当年第几周: %(woy)s | |
当周第几天 (0:周一): %(weekday)s |
时 00->24: %(h24)s | |
时 00->12: %(h12)s | |
分: %(min)s | |
秒: %(sec)s |
上一篇: 编写优秀的单元测试(四)测试替身