mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
add product sequence
This commit is contained in:
@@ -114,6 +114,40 @@ class AppThemeConfigSettings(models.TransientModel):
|
||||
raise Warning(e)
|
||||
return True
|
||||
|
||||
def remove_product(self):
|
||||
to_removes = [
|
||||
# 清除产品数据
|
||||
['product.product', ],
|
||||
['product.template', ],
|
||||
]
|
||||
try:
|
||||
for line in to_removes :
|
||||
obj_name = line[0]
|
||||
obj = self.pool.get(obj_name)
|
||||
if obj and obj._table_exist:
|
||||
sql = "delete from %s" % obj._table
|
||||
self._cr.execute( sql)
|
||||
except Exception, e:
|
||||
raise Warning(e)
|
||||
return True
|
||||
|
||||
def remove_product_attribute(self):
|
||||
to_removes = [
|
||||
# 清除产品属性
|
||||
['product.attribute.value', ],
|
||||
['product.attribute', ],
|
||||
]
|
||||
try:
|
||||
for line in to_removes :
|
||||
obj_name = line[0]
|
||||
obj = self.pool.get(obj_name)
|
||||
if obj and obj._table_exist:
|
||||
sql = "delete from %s" % obj._table
|
||||
self._cr.execute( sql)
|
||||
except Exception, e:
|
||||
raise Warning(e)
|
||||
return True
|
||||
|
||||
@api.multi
|
||||
def remove_pos(self):
|
||||
to_removes = [
|
||||
@@ -154,6 +188,8 @@ class AppThemeConfigSettings(models.TransientModel):
|
||||
def remove_mrp(self):
|
||||
to_removes = [
|
||||
# 清除生产单据
|
||||
['mrp.workcenter.productivity', ],
|
||||
['mrp.workorder', ],
|
||||
['mrp.production.workcenter.line', ],
|
||||
['mrp.production', ],
|
||||
['mrp.production.product.line', ],
|
||||
|
||||
@@ -103,12 +103,18 @@
|
||||
class="btn btn-warning btn-lg" rel="nofollow" href="mailto:guohuadeng@hotmail.com"><span
|
||||
style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span>
|
||||
<i class="fa fa-envelope"></i> guohuadeng@hotmail.com</a>
|
||||
<p><h4>
|
||||
Via QQ: 300883</h4></p>
|
||||
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"
|
||||
class="btn btn-warning btn-lg" rel="nofollow" href="mailto:300883@qq.com"><span
|
||||
style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span>
|
||||
<i class="fa fa-envelope"></i> 300883@qq.com</a>
|
||||
</div>
|
||||
<div class="oe_mt16">
|
||||
<p><h4>
|
||||
Visit our website for more support.</h4></p>
|
||||
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"
|
||||
class="btn btn-warning btn-lg" rel="nofollow" href="http://www.sunpop.cn"><span
|
||||
class="btn btn-warning btn-lg" rel="nofollow" href="http://www.sunpop.cn" target="_blank"><span
|
||||
style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span>
|
||||
<i class="fa fa-web"></i>http://www.sunpop.cn</a>
|
||||
</div>
|
||||
|
||||
@@ -89,6 +89,12 @@
|
||||
<div>
|
||||
<button string="Delete All Sales Order" type="object" name="remove_sales"
|
||||
confirm="Please confirm to delete the select data?" class="oe_highlight"/>
|
||||
|
|
||||
<button string="Delete All Product" type="object" name="remove_product"
|
||||
confirm="Please confirm to delete the select data?" class="oe_highlight"/>
|
||||
|
|
||||
<button string="Delete All Product Attribute" type="object" name="remove_product_attribute"
|
||||
confirm="Please confirm to delete the select data?" class="oe_highlight"/>
|
||||
</div>
|
||||
<label string="POS"/>
|
||||
<div>
|
||||
|
||||
18
app_product_sequence/__init__.py
Normal file
18
app_product_sequence/__init__.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Created on 2017-10-28
|
||||
@author: 广州尚鹏,http://www.sunpop.cn
|
||||
@email: 300883@qq.com
|
||||
@resource of Sunpop
|
||||
Odoo10离线中文用户手册下载
|
||||
http://www.sunpop.cn/odoo10_user_manual_document_offline/
|
||||
Odoo10离线开发手册下载-含python教程,jquery参考,Jinja2模板,PostgresSQL参考(odoo开发必备)
|
||||
http://www.sunpop.cn/odoo10_developer_document_offline/
|
||||
|
||||
@description:
|
||||
'''
|
||||
|
||||
import models
|
||||
import controllers
|
||||
from .hooks import pre_init_hook
|
||||
|
||||
60
app_product_sequence/__openerp__.py
Normal file
60
app_product_sequence/__openerp__.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Created on 2017-11-05
|
||||
# author: 广州尚鹏,http://www.sunpop.cn
|
||||
# email: 300883@qq.com
|
||||
# resource of Sunpop
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
# Odoo在线中文用户手册(长期更新)
|
||||
# http://www.sunpop.cn/documentation/user/10.0/zh_CN/index.html
|
||||
|
||||
# Odoo10离线中文用户手册下载
|
||||
# http://www.sunpop.cn/odoo10_user_manual_document_offline/
|
||||
# Odoo10离线开发手册下载-含python教程,jquery参考,Jinja2模板,PostgresSQL参考(odoo开发必备)
|
||||
# http://www.sunpop.cn/odoo10_developer_document_offline/
|
||||
# description:
|
||||
{
|
||||
'name': 'App Product Auto Sequence, Auto Code(Variants Supported)',
|
||||
'summary': 'Auto Internal Reference.',
|
||||
"version": '10.0.2.2',
|
||||
'category': 'Sales',
|
||||
'author': 'Sunpop.cn',
|
||||
'website': 'http://www.sunpop.cn',
|
||||
'license': 'AGPL-3',
|
||||
'sequence': 0,
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
'application': True,
|
||||
'images': ['static/description/set2.jpg'],
|
||||
'currency': 'EUR',
|
||||
'price': 98,
|
||||
'description': u"""
|
||||
App Product Auto Sequence, Auto Code(Variants Supported)
|
||||
|
||||
This module allows to associate a sequence to the product reference.<br/>
|
||||
The reference (default code) is unique (SQL constraint) and required.<br/>
|
||||
Support Product with or without Variants.
|
||||
1.Auto Sequence or code for every product.自动产品编码。
|
||||
2.Auto Sequence or for every product variants, like product20171130-001.自动多规格产品编码,形式为 主产品编码-001。
|
||||
3.Product code must be Unique.产品编码强制要求唯一。
|
||||
4.Define different product type, each product type use own rule of sequence.可自定义产品类型,不同产品类型使用不同编码规则。
|
||||
5.Quick access in sale , inventory, system menu.可以在销售、库存、系统菜单中快速定义。
|
||||
6.Multi language support.<br/>多语种支持。
|
||||
""",
|
||||
'pre_init_hook': 'pre_init_hook',
|
||||
'depends': [
|
||||
'product',
|
||||
'sale',
|
||||
'stock',
|
||||
],
|
||||
'data': [
|
||||
# 视图
|
||||
'views/product_template_view.xml',
|
||||
'views/product_product_view.xml',
|
||||
'views/product_internal_type_view.xml',
|
||||
'data/product_sequence.xml',
|
||||
],
|
||||
'demo': [
|
||||
],
|
||||
}
|
||||
1
app_product_sequence/controllers/__init__.py
Normal file
1
app_product_sequence/controllers/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
import main
|
||||
1
app_product_sequence/controllers/main.py
Normal file
1
app_product_sequence/controllers/main.py
Normal file
@@ -0,0 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
59
app_product_sequence/data/product_sequence.xml
Normal file
59
app_product_sequence/data/product_sequence.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<data noupdate="0">
|
||||
<!-- 更新序号规则 Auto Internal Reference. -->
|
||||
<!-- 所有的 Dapeng All Products. -->
|
||||
<record id="seq_product_auto" model="ir.sequence">
|
||||
<field name="name">Sequence for All Products</field>
|
||||
<field name="code">product.product</field>
|
||||
<field name="prefix">P%(y)s%(month)s</field>
|
||||
<field name="padding">5</field>
|
||||
<field name="company_id" eval="False"/>
|
||||
<field name="initial">True</field>
|
||||
</record>
|
||||
<!-- 制造的成品 Dapeng manufactured Products. -->
|
||||
<record id="seq_manufacture" model="ir.sequence">
|
||||
<field name="name">Sequence for Manufactured Product</field>
|
||||
<field name="code">product.product</field>
|
||||
<field name="prefix">D%(y)s%(month)s</field>
|
||||
<field name="padding">5</field>
|
||||
<field name="company_id" eval="False"/>
|
||||
<field name="initial">True</field>
|
||||
</record>
|
||||
<!-- 制造的原料 Components.-->
|
||||
<record id="seq_component" model="ir.sequence">
|
||||
<field name="name">Sequence for Components Product</field>
|
||||
<field name="code">product.product</field>
|
||||
<field name="prefix">C%(y)s%(month)s</field>
|
||||
<field name="padding">5</field>
|
||||
<field name="company_id" eval="False"/>
|
||||
<field name="initial">True</field>
|
||||
</record>
|
||||
<!-- 采购的成品 Sourced Products.-->
|
||||
<record id="seq_sourced" model="ir.sequence">
|
||||
<field name="name">Sequence for Sourced Product</field>
|
||||
<field name="code">product.product</field>
|
||||
<field name="prefix">S%(y)s%(month)s</field>
|
||||
<field name="padding">5</field>
|
||||
<field name="company_id" eval="False"/>
|
||||
<field name="initial">True</field>
|
||||
</record>
|
||||
|
||||
<!-- internal_type 数据-->
|
||||
<record id="internal_type_manufacture" model="product.internal.type">
|
||||
<field name="name">Manufactured Product</field>
|
||||
<field name="description">Set prefix as "D" in link sequence</field>
|
||||
<field name="link_sequence" ref="seq_manufacture"/>
|
||||
</record>
|
||||
<record id="internal_type_component" model="product.internal.type">
|
||||
<field name="name">Components Product</field>
|
||||
<field name="description">Set prefix as "C" in link sequence</field>
|
||||
<field name="link_sequence" ref="seq_component"/>
|
||||
</record>
|
||||
<record id="internal_type_sourced" model="product.internal.type">
|
||||
<field name="name">Sourced Product</field>
|
||||
<field name="description">Set prefix as "S" in link sequence</field>
|
||||
<field name="link_sequence" ref="seq_sourced"/>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
34
app_product_sequence/hooks.py
Normal file
34
app_product_sequence/hooks.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Created on 2017-11-05
|
||||
# author: 广州尚鹏,http://www.sunpop.cn
|
||||
# email: 300883@qq.com
|
||||
# resource of Sunpop
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
# Odoo在线中文用户手册(长期更新)
|
||||
# http://www.sunpop.cn/documentation/user/10.0/zh_CN/index.html
|
||||
|
||||
# Odoo10离线中文用户手册下载
|
||||
# http://www.sunpop.cn/odoo10_user_manual_document_offline/
|
||||
# Odoo10离线开发手册下载-含python教程,jquery参考,Jinja2模板,PostgresSQL参考(odoo开发必备)
|
||||
# http://www.sunpop.cn/odoo10_developer_document_offline/
|
||||
# description:
|
||||
|
||||
def pre_init_hook(cr):
|
||||
"""
|
||||
Updates existing codes matching the default 'New' or
|
||||
empty. Primarily this ensures installation does not
|
||||
fail for demo data.
|
||||
:param cr: database cursor
|
||||
:return: void
|
||||
"""
|
||||
cr.execute("UPDATE product_product "
|
||||
"SET default_code = '!!DP!!' || id "
|
||||
"WHERE default_code IS NULL OR default_code = 'New';")
|
||||
|
||||
cr.execute("UPDATE product_template "
|
||||
"Set default_code = "
|
||||
"(select default_code from product_product "
|
||||
"where product_product.product_tmpl_id = product_template.id limit 1)"
|
||||
"WHERE default_code IS NULL OR default_code = 'New';")
|
||||
20
app_product_sequence/i18n/en_GB.po
Normal file
20
app_product_sequence/i18n/en_GB.po
Normal file
@@ -0,0 +1,20 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * product
|
||||
#
|
||||
# Translators:
|
||||
# Ivan Deng <300883@qq.com>
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo 10.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2016-11-22 14:03+0000\n"
|
||||
"PO-Revision-Date: 2016-01-30 10:36+0000\n"
|
||||
"Last-Translator: Ivan Deng\n"
|
||||
"Language-Team: English (United Kingdom) (http://www.transifex.com/odoo/"
|
||||
"odoo-10/language/en_GB/)\n"
|
||||
"Language: en_GB\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
131
app_product_sequence/i18n/zh_CN.po
Normal file
131
app_product_sequence/i18n/zh_CN.po
Normal file
@@ -0,0 +1,131 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * app_product_sequence
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 10.0+e-20171014\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2017-11-05 12:11+0000\n"
|
||||
"PO-Revision-Date: 2017-11-05 12:11+0000\n"
|
||||
"Last-Translator: <>\n"
|
||||
"Language-Team: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: \n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_internal_type_create_uid
|
||||
msgid "Created by"
|
||||
msgstr "创建人"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_internal_type_create_date
|
||||
msgid "Created on"
|
||||
msgstr "创建时间"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_internal_type_description
|
||||
msgid "Description"
|
||||
msgstr "说明"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_internal_type_display_name
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_internal_type_name
|
||||
msgid "Display Name"
|
||||
msgstr "显示名称"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_internal_type_id
|
||||
msgid "ID"
|
||||
msgstr "ID"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_product_default_code_index
|
||||
msgid "Internal Reference Index"
|
||||
msgstr "Varient序号"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_product_default_code_stored
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_template_default_code_stored
|
||||
msgid "Internal Reference Stored"
|
||||
msgstr "主产品编码"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_product_internal_type
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_template_internal_type
|
||||
msgid "Internal Type"
|
||||
msgstr "编码类型"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_internal_type___last_update
|
||||
msgid "Last Modified on"
|
||||
msgstr "最后修改日"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_internal_type_write_uid
|
||||
msgid "Last Updated by"
|
||||
msgstr "最后更新人"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_internal_type_write_date
|
||||
msgid "Last Updated on"
|
||||
msgstr "最后更新时间"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,field_description:app_product_sequence.field_product_internal_type_link_sequence
|
||||
msgid "Link Sequence"
|
||||
msgstr "使用的序列"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: code:addons/app_product_sequence/models/product_template.py:38
|
||||
#, python-format
|
||||
msgid "Please save product first before adding varients!"
|
||||
msgstr "增加产品变体前,请先保存当前产品!"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model.fields,help:app_product_sequence.field_product_internal_type_sequence_prefix
|
||||
msgid "Prefix value of the record for the sequence"
|
||||
msgstr "序列记录的前缀"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model,name:app_product_sequence.model_product_product
|
||||
msgid "Product"
|
||||
msgstr "产品"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.actions.act_window,name:app_product_sequence.internal_type_action
|
||||
#: model:ir.ui.menu,name:app_product_sequence.menu_internal_type_action_sale
|
||||
#: model:ir.ui.menu,name:app_product_sequence.menu_internal_type_action_stock
|
||||
#: model:ir.ui.menu,name:app_product_sequence.menu_internal_type_action_sys
|
||||
#: model:ir.ui.view,arch_db:app_product_sequence.product_internal_type_tree_view
|
||||
msgid "Product Internal Type"
|
||||
msgstr "产品编码类型"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model,name:app_product_sequence.model_product_template
|
||||
msgid "Product Template"
|
||||
msgstr "产品模板"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: code:addons/app_product_sequence/models/product_product.py:80
|
||||
#, python-format
|
||||
msgid "Product varient can only create in Product view!"
|
||||
msgstr "请在产品管理页面增加产品的多属性!"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: sql_constraint:product.internal.type:0
|
||||
msgid "The Link Sequence must be unique"
|
||||
msgstr "使用的序列不可重复!"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: sql_constraint:product.product:0
|
||||
msgid "The reference must be unique"
|
||||
msgstr "产品内部编码不可重复!"
|
||||
|
||||
#. module: app_product_sequence
|
||||
#: model:ir.model,name:app_product_sequence.model_product_internal_type
|
||||
msgid "product.internal.type"
|
||||
msgstr "product.internal.type"
|
||||
|
||||
4
app_product_sequence/models/__init__.py
Normal file
4
app_product_sequence/models/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import product_template
|
||||
import product_product
|
||||
import product_internal_type
|
||||
36
app_product_sequence/models/product_internal_type.py
Normal file
36
app_product_sequence/models/product_internal_type.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Created on 2017-11-05
|
||||
# author: 广州尚鹏,http://www.sunpop.cn
|
||||
# email: 300883@qq.com
|
||||
# resource of Sunpop
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
# Odoo在线中文用户手册(长期更新)
|
||||
# http://www.sunpop.cn/documentation/user/10.0/zh_CN/index.html
|
||||
|
||||
# Odoo10离线中文用户手册下载
|
||||
# http://www.sunpop.cn/odoo10_user_manual_document_offline/
|
||||
# Odoo10离线开发手册下载-含python教程,jquery参考,Jinja2模板,PostgresSQL参考(odoo开发必备)
|
||||
# http://www.sunpop.cn/odoo10_developer_document_offline/
|
||||
# description:
|
||||
|
||||
from openerp import api, fields, models, _
|
||||
|
||||
|
||||
class ProductInternalType(models.Model):
|
||||
_name = "product.internal.type"
|
||||
|
||||
name = fields.Char('Display Name',default='Normal')
|
||||
description = fields.Char('Description')
|
||||
# 因为default_code有odoo的处理方式,影响面大,故会将其另存到 default_code_stored
|
||||
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)
|
||||
|
||||
# _sql_constraints = [
|
||||
# ('uniq_link_sequence',
|
||||
# 'unique(link_sequence)',
|
||||
# 'The Link Sequence must be unique'),
|
||||
# ]
|
||||
83
app_product_sequence/models/product_product.py
Normal file
83
app_product_sequence/models/product_product.py
Normal file
@@ -0,0 +1,83 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Created on 2017-11-05
|
||||
# author: 广州尚鹏,http://www.sunpop.cn
|
||||
# email: 300883@qq.com
|
||||
# resource of Sunpop
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
# Odoo在线中文用户手册(长期更新)
|
||||
# http://www.sunpop.cn/documentation/user/10.0/zh_CN/index.html
|
||||
|
||||
# Odoo10离线中文用户手册下载
|
||||
# http://www.sunpop.cn/odoo10_user_manual_document_offline/
|
||||
# Odoo10离线开发手册下载-含python教程,jquery参考,Jinja2模板,PostgresSQL参考(odoo开发必备)
|
||||
# http://www.sunpop.cn/odoo10_developer_document_offline/
|
||||
# description:
|
||||
from openerp import models, fields, api, exceptions, _
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
default_code = fields.Char('Internal Reference', index=True, readonly=True, default='New', copy=False)
|
||||
default_code_index = fields.Integer('Internal Reference Index', readonly=True)
|
||||
|
||||
_sql_constraints = [
|
||||
('uniq_default_code',
|
||||
'unique(default_code)',
|
||||
'The reference must be unique'),
|
||||
]
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
# todo: but 先建空白产品后,编辑给2个以上变体,序号会少个 -1
|
||||
# code_index: 当没有变体现时,值为0,有变体时,为该变体序号
|
||||
if 'default_code' not in vals or vals['default_code'] == 'New':
|
||||
code_index = 0
|
||||
if 'product_tmpl_id' in vals:
|
||||
template = self.env['product.template'].search([('id', '=', vals['product_tmpl_id'])], limit=1)
|
||||
mylen = len(template.product_variant_ids)
|
||||
# created from product_template
|
||||
if 'product_tmpl_id' in vals:
|
||||
template = self.env['product.template'].search([('id', '=', vals['product_tmpl_id'])], limit=1)
|
||||
attr = vals['attribute_value_ids'][0][2]
|
||||
if not(attr):
|
||||
# 没有属性值,则是单规格产品。attribute_value_ids格式为[6,0,[]]。多规格时,attribute_value_ids格式为[6,0,[x]]
|
||||
code_index = 0
|
||||
vals['default_code_index'] = code_index
|
||||
vals['default_code'] = template.default_code_stored
|
||||
elif mylen == 0:
|
||||
# 有属性值了,自己是第一个规格
|
||||
code_index = 1
|
||||
vals['default_code_index'] = code_index
|
||||
vals['default_code'] = template.default_code_stored + '-%03d'%(code_index)
|
||||
elif mylen == 1:
|
||||
# 已存在1个,当存在的1个有属性时,要改已存在的product值
|
||||
code_index = template.product_variant_ids[:1].default_code_index
|
||||
if template.product_variant_ids[:1].attribute_value_ids:
|
||||
if code_index == 0:
|
||||
code_index = 1
|
||||
template.product_variant_ids[:1].default_code_index = code_index
|
||||
template.product_variant_ids[:1].default_code = template.default_code_stored + '-%03d'%(code_index)
|
||||
# 接着改当前操作的product值
|
||||
code_index = code_index + 1
|
||||
vals['default_code_index'] = code_index
|
||||
vals['default_code'] = template.default_code_stored + '-%03d'%(code_index)
|
||||
else:
|
||||
# 找到最大的序号
|
||||
variant_max = max(template.product_variant_ids,key=lambda x: x['default_code_index'])
|
||||
code_index = variant_max['default_code_index'] + 1
|
||||
vals['default_code_index'] = code_index
|
||||
vals['default_code'] = template.default_code_stored + '-%03d'%(code_index)
|
||||
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()
|
||||
return super(ProductProduct, self).create(vals)
|
||||
|
||||
@api.multi
|
||||
def copy(self, default=None):
|
||||
if len(self.product_tmpl_id.product_variant_ids)>1 :
|
||||
raise exceptions.ValidationError(_('Product varient can only create in Product view!'))
|
||||
return super(ProductProduct, self).copy(default=None)
|
||||
60
app_product_sequence/models/product_template.py
Normal file
60
app_product_sequence/models/product_template.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Created on 2017-11-05
|
||||
# author: 广州尚鹏,http://www.sunpop.cn
|
||||
# email: 300883@qq.com
|
||||
# resource of Sunpop
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
# Odoo在线中文用户手册(长期更新)
|
||||
# http://www.sunpop.cn/documentation/user/10.0/zh_CN/index.html
|
||||
|
||||
# Odoo10离线中文用户手册下载
|
||||
# http://www.sunpop.cn/odoo10_user_manual_document_offline/
|
||||
# Odoo10离线开发手册下载-含python教程,jquery参考,Jinja2模板,PostgresSQL参考(odoo开发必备)
|
||||
# http://www.sunpop.cn/odoo10_developer_document_offline/
|
||||
# description:
|
||||
|
||||
from openerp import api, fields, models, exceptions, _
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
_name = "product.template"
|
||||
_inherit = ['product.template']
|
||||
|
||||
internal_type = fields.Many2one(
|
||||
'product.internal.type', 'Internal Type',
|
||||
auto_join=True, required=True)
|
||||
|
||||
default_code = fields.Char(
|
||||
'Internal Reference', compute='_compute_default_code',
|
||||
inverse='_set_default_code', store=True, readonly=True,
|
||||
default='New', copy=False)
|
||||
# 因为default_code有odoo的处理方式,影响面大,故会将其另存到 default_code_stored
|
||||
default_code_stored = fields.Char('Internal Reference Stored',default='New')
|
||||
|
||||
@api.model
|
||||
def create(self, vals):
|
||||
if 'attribute_line_ids' in vals:
|
||||
if len(vals['attribute_line_ids'])>0:
|
||||
raise exceptions.ValidationError(_('Please save product first before adding varients!'))
|
||||
if 'default_code' not in vals or vals['default_code'] == 'New':
|
||||
sequence = self.env['product.internal.type'].search([('id', '=', vals['internal_type'])], limit=1)
|
||||
vals['default_code'] = sequence.link_sequence.next_by_id()
|
||||
vals['default_code_stored'] = vals['default_code']
|
||||
return super(ProductTemplate, self).create(vals)
|
||||
|
||||
@api.depends('product_variant_ids', 'product_variant_ids.default_code')
|
||||
def _compute_default_code(self):
|
||||
unique_variants = self.filtered(lambda template: len(template.product_variant_ids) == 1)
|
||||
for template in unique_variants:
|
||||
template.default_code = template.product_variant_ids.default_code
|
||||
for template in (self):
|
||||
if len(template.product_variant_ids)>1:
|
||||
template.default_code = ''
|
||||
|
||||
@api.one
|
||||
def _set_default_code(self):
|
||||
if len(self.product_variant_ids) == 1:
|
||||
self.product_variant_ids.default_code = self.default_code_stored
|
||||
|
||||
BIN
app_product_sequence/static/description/icon.png
Normal file
BIN
app_product_sequence/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
98
app_product_sequence/static/description/index.html
Normal file
98
app_product_sequence/static/description/index.html
Normal file
@@ -0,0 +1,98 @@
|
||||
<section class="oe_container oe_dark">
|
||||
<div class="oe_row oe_padded">
|
||||
<h2 class="oe_slogan" style="color:#875A7B;">App Product Auto Sequence, Auto Code(Variants Supported)</h2>
|
||||
<div>
|
||||
<p>
|
||||
This module allows to associate a sequence to the product reference.<br/>
|
||||
The reference (default code) is unique (SQL constraint) and required.<br/>
|
||||
Support Product with or without Variants.
|
||||
</p>
|
||||
<ul>
|
||||
<li>
|
||||
Auto Sequence or code for every product.
|
||||
</li>
|
||||
<li>
|
||||
Auto Sequence or for every product variants, like product20171130-001.
|
||||
</li>
|
||||
<li>
|
||||
Product code must be Unique.
|
||||
</li>
|
||||
<li>
|
||||
Define different product type, each product type use own rule of sequence.
|
||||
</li>
|
||||
<li>
|
||||
Quick access in sale , inventory, system menu.
|
||||
</li>
|
||||
<li>
|
||||
Multi language support.
|
||||
</li>
|
||||
</ul>
|
||||
<div>
|
||||
<img class="oe_picture oe_screenshot" src="set1.jpg">
|
||||
</div>
|
||||
<div>
|
||||
<img class="oe_picture oe_screenshot" src="set2.jpg">
|
||||
</div>
|
||||
<h2>Sample Rule:</h2>
|
||||
<p>
|
||||
D171100001 for Manufactured Products.<br/>
|
||||
C171000001 for Components Products.<br/>
|
||||
S171000001 for Sourced Products.<br/>
|
||||
17-year, 10-month.<br/>
|
||||
</p>
|
||||
<p>
|
||||
Sepcial for variants. add [-00?]<br/>
|
||||
</p>
|
||||
<h2>Installation:</h2>
|
||||
<p>
|
||||
Prior to installing this module, if you have any existing products you should ensure they already have a
|
||||
unique reference (or no reference) set.<br/>
|
||||
Products with a default_code of '/' or empty will automatically be assigned a code of "!!DP!!" followed
|
||||
by the system id for that product.<br/>
|
||||
Otherwise the setting of the unique constraint will fail and the module will fail to install.<br/>
|
||||
|
||||
Notice:<br/>
|
||||
Odoo product variants is very special.<br/>
|
||||
When u create a product(not product template) with attribute, It would delete the first product, which
|
||||
have no attribute.
|
||||
So it's very normal that the first product variants begin wit ???-002.<br/>
|
||||
And we make a rule that the product variants can only create after you create normal product template.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="oe_container oe_separator">
|
||||
</section>
|
||||
|
||||
<section class="oe_container oe_dark">
|
||||
<div class="oe_row oe_spaced text-center">
|
||||
<div class="oe_span12">
|
||||
<h2 class="oe_slogan">Technical Help & Support</h2>
|
||||
</div>
|
||||
<div class="col-md-12 pad0">
|
||||
<div class="oe_mt16">
|
||||
<p><h4>
|
||||
For any type of technical help & support requests, Feel free to contact us</h4></p>
|
||||
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"
|
||||
class="btn btn-warning btn-lg" rel="nofollow" href="mailto:guohuadeng@hotmail.com"><span
|
||||
style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span>
|
||||
<i class="fa fa-envelope"></i> guohuadeng@hotmail.com</a>
|
||||
<p><h4>
|
||||
Via QQ: 300883</h4></p>
|
||||
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"
|
||||
class="btn btn-warning btn-lg" rel="nofollow" href="mailto:300883@qq.com"><span
|
||||
style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span>
|
||||
<i class="fa fa-envelope"></i> 300883@qq.com</a>
|
||||
</div>
|
||||
<div class="oe_mt16">
|
||||
<p><h4>
|
||||
Visit our website for more support.</h4></p>
|
||||
<a style="background: #002e5a none repeat scroll 0% 0%; color: rgb(255, 255, 255);position: relative; overflow: hidden;"
|
||||
class="btn btn-warning btn-lg" rel="nofollow" href="http://www.sunpop.cn" target="_blank"><span
|
||||
style="height: 354px; width: 354px; top: -147.433px; left: -6.93335px;" class="o_ripple"></span>
|
||||
<i class="fa fa-web"></i>http://www.sunpop.cn</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
BIN
app_product_sequence/static/description/set1.jpg
Normal file
BIN
app_product_sequence/static/description/set1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 151 KiB |
BIN
app_product_sequence/static/description/set2.jpg
Normal file
BIN
app_product_sequence/static/description/set2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 155 KiB |
15
app_product_sequence/tests/__init__.py
Normal file
15
app_product_sequence/tests/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Created on 2017-10-28
|
||||
@author: 广州尚鹏,http://www.sunpop.cn
|
||||
@email: 300883@qq.com
|
||||
@resource of Sunpop
|
||||
Odoo10离线中文用户手册下载
|
||||
http://www.sunpop.cn/odoo10_user_manual_document_offline/
|
||||
Odoo10离线开发手册下载-含python教程,jquery参考,Jinja2模板,PostgresSQL参考(odoo开发必备)
|
||||
http://www.sunpop.cn/odoo10_developer_document_offline/
|
||||
|
||||
@description:
|
||||
'''
|
||||
|
||||
from . import test_product_sequence
|
||||
59
app_product_sequence/tests/test_product_sequence.py
Normal file
59
app_product_sequence/tests/test_product_sequence.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Created on 2017-10-28
|
||||
@author: 广州尚鹏,http://www.sunpop.cn
|
||||
@email: 300883@qq.com
|
||||
@resource of Sunpop
|
||||
Odoo10离线中文用户手册下载
|
||||
http://www.sunpop.cn/odoo10_user_manual_document_offline/
|
||||
Odoo10离线开发手册下载-含python教程,jquery参考,Jinja2模板,PostgresSQL参考(odoo开发必备)
|
||||
http://www.sunpop.cn/odoo10_developer_document_offline/
|
||||
|
||||
@description:
|
||||
'''
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
from ..hooks import pre_init_hook
|
||||
|
||||
|
||||
class TestProductSequence(TransactionCase):
|
||||
"""Tests for creating product with and without Product Sequence"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestProductSequence, self).setUp()
|
||||
self.product_product = self.env['product.product']
|
||||
|
||||
def test_product_create_with_default_code(self):
|
||||
product = self.product_product.create(dict(
|
||||
name="Apple",
|
||||
default_code='PROD01'
|
||||
))
|
||||
self.assertEqual(product.default_code, 'PROD01')
|
||||
|
||||
def test_product_create_without_default_code(self):
|
||||
product_1 = self.product_product.create(dict(
|
||||
name="Orange",
|
||||
default_code='/'))
|
||||
self.assertRegexpMatches(str(product_1.default_code), r'PR/*')
|
||||
|
||||
def test_product_copy(self):
|
||||
product_2 = self.product_product.create(dict(
|
||||
name="Apple",
|
||||
default_code='PROD02'
|
||||
))
|
||||
copy_product_2 = product_2.copy()
|
||||
self.assertEqual(copy_product_2.default_code, 'PROD02-copy')
|
||||
|
||||
def test_pre_init_hook(self):
|
||||
product_3 = self.product_product.create(dict(
|
||||
name="Apple",
|
||||
default_code='PROD03'
|
||||
))
|
||||
self.cr.execute(
|
||||
"update product_product set default_code='/' where id=%s"
|
||||
% (product_3.id,))
|
||||
product_3.invalidate_cache()
|
||||
self.assertEqual(product_3.default_code, '/')
|
||||
pre_init_hook(self.cr)
|
||||
product_3.invalidate_cache()
|
||||
self.assertEqual(product_3.default_code, '!!mig!!%s' % (product_3.id,))
|
||||
30
app_product_sequence/views/product_internal_type_view.xml
Normal file
30
app_product_sequence/views/product_internal_type_view.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!--产品内部类型list-->
|
||||
<record id="product_internal_type_tree_view" model="ir.ui.view">
|
||||
<field name="name">product.internal.type.tree</field>
|
||||
<field name="model">product.internal.type</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Product Internal Type" editable="top">
|
||||
<field name="name"/>
|
||||
<field name="link_sequence"/>
|
||||
<field name="sequence_prefix"/>
|
||||
<field name="description"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="internal_type_action" model="ir.actions.act_window">
|
||||
<field name="name">Product Internal Type</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">product.internal.type</field>
|
||||
<field name="view_mode">tree</field>
|
||||
</record>
|
||||
|
||||
<menuitem action="app_product_sequence.internal_type_action" id="menu_internal_type_action_sys" parent="base.next_id_5"/>
|
||||
<menuitem action="app_product_sequence.internal_type_action" id="menu_internal_type_action_sale"
|
||||
parent="sale.prod_config_main" sequence="6" groups="product.group_product_variant"/>
|
||||
<menuitem action="app_product_sequence.internal_type_action" id="menu_internal_type_action_stock"
|
||||
parent="stock.menu_stock_inventory_control" sequence="3" groups="product.group_product_variant"/>
|
||||
</data>
|
||||
</openerp>
|
||||
16
app_product_sequence/views/product_product_view.xml
Normal file
16
app_product_sequence/views/product_product_view.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!--产品list-->
|
||||
<record id="product_product_tree_view" model="ir.ui.view">
|
||||
<field name="name">product.product.tree</field>
|
||||
<field name="model">product.product</field>
|
||||
<field name="inherit_id" ref="product.product_product_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='name']" position="after">
|
||||
<field name="internal_type"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
27
app_product_sequence/views/product_template_view.xml
Normal file
27
app_product_sequence/views/product_template_view.xml
Normal file
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!--产品list-->
|
||||
<record id="product_template_tree_view" model="ir.ui.view">
|
||||
<field name="name">product.template.product.tree</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="product.product_template_tree_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='type']" position="before">
|
||||
<field name="internal_type"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<!--产品Form-->
|
||||
<record id="product_template_form_view" model="ir.ui.view">
|
||||
<field name="name">product.template.common.form</field>
|
||||
<field name="model">product.template</field>
|
||||
<field name="inherit_id" ref="product.product_template_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='type']" position="before">
|
||||
<field name="internal_type"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user