diff --git a/app_product_sequence/data/product_sequence_felive.xml b/app_product_sequence/data/product_sequence_felive.xml index 4a502df7..058eb1ce 100644 --- a/app_product_sequence/data/product_sequence_felive.xml +++ b/app_product_sequence/data/product_sequence_felive.xml @@ -52,46 +52,46 @@ - 制造的成品 + 成品 cp product 1 0 - Set prefix as "CP" in link sequence + 制造的成品。如:床,桌子 - 制造的板件 + 板件 bj product 0 0 - Set prefix as "BJ" in link sequence + 制造的半成品。如:床的左侧板,柜子的顶板 - 制造用原材料(板材) + 原材料(板材) bc product 0 1 - Set prefix as "BC" in link sequence + 制造所需的原材料,不可直接销售。如:中纤板(厚14mm) - 外购成品(五金等) + 外购成品 cl product 1 1 - Set prefix as "CL" in link sequence + 采购后可直接销售,也可当原材料的成品。如:门把手 diff --git a/app_product_sequence/i18n/zh_CN.po b/app_product_sequence/i18n/zh_CN.po index d44fb32b..396e4a44 100644 --- a/app_product_sequence/i18n/zh_CN.po +++ b/app_product_sequence/i18n/zh_CN.po @@ -105,7 +105,7 @@ msgstr "主产品编码" #: 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 "内部(编码)类型" +msgstr "内部类型(编码)" #. module: app_product_sequence #: model:ir.model.fields,field_description:app_product_sequence.field_product_internal_type___last_update @@ -156,7 +156,7 @@ msgstr "产品类别" #: model:ir.ui.view,arch_db:app_product_sequence.product_internal_type_form_view #: model:ir.ui.view,arch_db:app_product_sequence.product_internal_type_tree_view msgid "Product Internal Type" -msgstr "产品内部(编码)类型" +msgstr "内部类型(编码)" #. module: app_product_sequence #: model:ir.model,name:app_product_sequence.model_product_template diff --git a/app_product_sequence/models/product_product.py b/app_product_sequence/models/product_product.py index 60839c7b..99b49892 100644 --- a/app_product_sequence/models/product_product.py +++ b/app_product_sequence/models/product_product.py @@ -20,7 +20,7 @@ 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 = fields.Char('Internal Reference', index=True, readonly=True, default=lambda self: _('New'), copy=False) default_code_index = fields.Integer('Internal Reference Index', readonly=True) _sql_constraints = [ diff --git a/app_product_sequence/views/product_template_view.xml b/app_product_sequence/views/product_template_view.xml index 94a811ad..a790db68 100644 --- a/app_product_sequence/views/product_template_view.xml +++ b/app_product_sequence/views/product_template_view.xml @@ -1,7 +1,7 @@ - + product.template.product.tree product.template diff --git a/app_product_type_sequence/__init__.py b/app_product_type_sequence/__init__.py new file mode 100644 index 00000000..32e57aa9 --- /dev/null +++ b/app_product_type_sequence/__init__.py @@ -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 + diff --git a/app_product_type_sequence/__openerp__.py b/app_product_type_sequence/__openerp__.py new file mode 100644 index 00000000..2094e5d5 --- /dev/null +++ b/app_product_type_sequence/__openerp__.py @@ -0,0 +1,66 @@ +# -*- 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 Internal Type,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': 2, + '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.
+ The reference (default code) is unique (SQL constraint) and required.
+ 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.
多语种支持。 + 7.Setup default Auto Sequence for each product category + """, + 'pre_init_hook': 'pre_init_hook', + 'depends': [ + 'product', + 'stock', + 'sale', + 'purchase', + 'mrp', + ], + 'data': [ + # 视图 + "security/ir.model.access.csv", + # "security/security.xml", + 'views/product_template_view.xml', + 'views/product_product_view.xml', + 'views/product_category_view.xml', + 'views/product_internal_type_view.xml', + 'data/product_sequence.xml', + ], + 'demo': [ + ], +} diff --git a/app_product_type_sequence/controllers/__init__.py b/app_product_type_sequence/controllers/__init__.py new file mode 100644 index 00000000..8ee9bae1 --- /dev/null +++ b/app_product_type_sequence/controllers/__init__.py @@ -0,0 +1 @@ +import main diff --git a/app_product_type_sequence/controllers/main.py b/app_product_type_sequence/controllers/main.py new file mode 100644 index 00000000..40a96afc --- /dev/null +++ b/app_product_type_sequence/controllers/main.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/app_product_type_sequence/data/product_sequence.xml b/app_product_type_sequence/data/product_sequence.xml new file mode 100644 index 00000000..c0c7f9f6 --- /dev/null +++ b/app_product_type_sequence/data/product_sequence.xml @@ -0,0 +1,109 @@ + + + + + + + Sequence for All Products + product.product + P%(y)s%(month)s + 5 + + True + + + + Sequence for Manufactured Product + product.product + CP%(y)s%(month)s + 5 + + True + + + + Sequence for Manufactured Components + product.product + BJ%(y)s%(month)s + 5 + + True + + + + Sequence for Sourced Material + product.product + BC%(y)s%(month)s + 5 + + True + + + + Sequence for Sourced Product + product.product + CL%(y)s%(month)s + 5 + + True + + + + + + + Manufactured Product + cp + product + 1 + 0 + + Set prefix as "CP" in link sequence + + + + + Manufactured Components + bj + product + 0 + 0 + + Set prefix as "BJ" in link sequence + + + + + Components Product + bc + product + 0 + 1 + + Set prefix as "BC" in link sequence + + + + + Sourced Product + cl + product + 1 + 1 + + Set prefix as "CL" in link sequence + + + + + + + internal_type + product.template + default + + + + + + diff --git a/app_product_type_sequence/data/product_sequence_dp.xml b/app_product_type_sequence/data/product_sequence_dp.xml new file mode 100644 index 00000000..ae13b86c --- /dev/null +++ b/app_product_type_sequence/data/product_sequence_dp.xml @@ -0,0 +1,84 @@ + + + + + + + Sequence for All Products + product.product + P%(y)s%(month)s + 5 + + True + + + + Sequence for Manufactured Product + product.product + D%(y)s%(month)s + 5 + + True + + + + Sequence for Components Product + product.product + C%(y)s%(month)s + 5 + + True + + + + Sequence for Sourced Product + product.product + S%(y)s%(month)s + 5 + + True + + + + + Manufactured Product + d + product + 1 + 0 + + Set prefix as "D" in link sequence + + + + Components Product + c + product + 0 + 1 + + Set prefix as "C" in link sequence + + + + Sourced Product + s + product + 1 + 1 + + Set prefix as "S" in link sequence + + + + + + internal_type + product.template + default + + + + + + diff --git a/app_product_type_sequence/data/product_sequence_felive.xml b/app_product_type_sequence/data/product_sequence_felive.xml new file mode 100644 index 00000000..4a502df7 --- /dev/null +++ b/app_product_type_sequence/data/product_sequence_felive.xml @@ -0,0 +1,109 @@ + + + + + + + Sequence for All Products + product.product + P%(y)s%(month)s + 5 + + True + + + + Sequence for Manufactured Product + product.product + CP%(y)s%(month)s + 5 + + True + + + + Sequence for Manufactured Components + product.product + BJ%(y)s%(month)s + 5 + + True + + + + Sequence for Sourced Material + product.product + BC%(y)s%(month)s + 5 + + True + + + + Sequence for Sourced Product + product.product + CL%(y)s%(month)s + 5 + + True + + + + + + + 制造的成品 + cp + product + 1 + 0 + + Set prefix as "CP" in link sequence + + + + + 制造的板件 + bj + product + 0 + 0 + + Set prefix as "BJ" in link sequence + + + + + 制造用原材料(板材) + bc + product + 0 + 1 + + Set prefix as "BC" in link sequence + + + + + 外购成品(五金等) + cl + product + 1 + 1 + + Set prefix as "CL" in link sequence + + + + + + + internal_type + product.template + default + + + + + + diff --git a/app_product_type_sequence/data/product_sequence_origin.xml b/app_product_type_sequence/data/product_sequence_origin.xml new file mode 100644 index 00000000..c0c7f9f6 --- /dev/null +++ b/app_product_type_sequence/data/product_sequence_origin.xml @@ -0,0 +1,109 @@ + + + + + + + Sequence for All Products + product.product + P%(y)s%(month)s + 5 + + True + + + + Sequence for Manufactured Product + product.product + CP%(y)s%(month)s + 5 + + True + + + + Sequence for Manufactured Components + product.product + BJ%(y)s%(month)s + 5 + + True + + + + Sequence for Sourced Material + product.product + BC%(y)s%(month)s + 5 + + True + + + + Sequence for Sourced Product + product.product + CL%(y)s%(month)s + 5 + + True + + + + + + + Manufactured Product + cp + product + 1 + 0 + + Set prefix as "CP" in link sequence + + + + + Manufactured Components + bj + product + 0 + 0 + + Set prefix as "BJ" in link sequence + + + + + Components Product + bc + product + 0 + 1 + + Set prefix as "BC" in link sequence + + + + + Sourced Product + cl + product + 1 + 1 + + Set prefix as "CL" in link sequence + + + + + + + internal_type + product.template + default + + + + + + diff --git a/app_product_type_sequence/hooks.py b/app_product_type_sequence/hooks.py new file mode 100644 index 00000000..a4d9d2f1 --- /dev/null +++ b/app_product_type_sequence/hooks.py @@ -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';") diff --git a/app_product_type_sequence/i18n/zh_CN.po b/app_product_type_sequence/i18n/zh_CN.po new file mode 100644 index 00000000..47a020b7 --- /dev/null +++ b/app_product_type_sequence/i18n/zh_CN.po @@ -0,0 +1,221 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * app_product_type_sequence +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0-20171107\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-12-18 19:02+0000\n" +"PO-Revision-Date: 2017-12-18 19:02+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_type_sequence +#: model:ir.model.fields,help:app_product_type_sequence.field_product_internal_type_type +msgid "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." +msgstr "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." + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_purchase_ok +msgid "Can be Purchased" +msgstr "可用于采购" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_rental +msgid "Can be Rent" +msgstr "可用于出租" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_sale_ok +msgid "Can be Sold" +msgstr "可用于销售" + +#. module: app_product_type_sequence +#: code:addons/app_product_type_sequence/models/product_internal_type.py:34 +#: selection:product.internal.type,type:0 +#, python-format +msgid "Consumable" +msgstr "可消耗" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_create_uid +msgid "Created by" +msgstr "创建人" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_create_date +msgid "Created on" +msgstr "创建时间" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_category_internal_type +msgid "Default Internal Type" +msgstr "默认产品内部类型" + +#. module: app_product_type_sequence +#: model:ir.ui.view,arch_db:app_product_type_sequence.product_internal_type_form_view +msgid "Auto Set Product's Value To:" +msgstr "自动设置产品默认参数为:" + +#. module: app_product_type_sequence +#: model:ir.model.fields,help:app_product_type_sequence.field_product_internal_type_route_ids +msgid "Depending on the modules installed, this will allow you to define the route of the product: whether it will be bought, manufactured, MTO/MTS,..." +msgstr "取决于安装的模块,它允许在产品定义路线:购买,制造,MTO/MTS,等等..." + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_description +msgid "Description" +msgstr "说明" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_display_name +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_name +#: model:ir.ui.view,arch_db:app_product_type_sequence.product_internal_type_form_view +msgid "Display Name" +msgstr "显示名称" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_id +msgid "ID" +msgstr "ID" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_product_default_code_index +msgid "Internal Reference Index" +msgstr "Varient序号" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_product_default_code_stored +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_template_default_code_stored +msgid "Internal Reference Stored" +msgstr "主产品编码" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_product_internal_type +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_template_internal_type +msgid "Internal Type" +msgstr "内部(编码)类型" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type___last_update +msgid "Last Modified on" +msgstr "最后修改日" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_write_uid +msgid "Last Updated by" +msgstr "最后更新人" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_write_date +msgid "Last Updated on" +msgstr "最后更新时间" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_link_sequence +msgid "Link Sequence" +msgstr "使用的序列" + +#. module: app_product_type_sequence +#: code:addons/app_product_type_sequence/models/product_template.py:41 +#, python-format +msgid "Please save product first before adding varients!" +msgstr "增加产品变体前,请先保存当前产品!" + +#. module: app_product_type_sequence +#: model:ir.model.fields,help:app_product_type_sequence.field_product_internal_type_sequence_prefix +msgid "Prefix value of the record for the sequence" +msgstr "序列记录的前缀" + +#. module: app_product_type_sequence +#: model:ir.model,name:app_product_type_sequence.model_product_product +msgid "Product" +msgstr "产品" + +#. module: app_product_type_sequence +#: model:ir.model,name:app_product_type_sequence.model_product_category +msgid "Product Category" +msgstr "产品类别" + +#. module: app_product_type_sequence +#: model:ir.actions.act_window,name:app_product_type_sequence.internal_type_action +#: model:ir.ui.menu,name:app_product_type_sequence.menu_internal_type_action_sale +#: model:ir.ui.menu,name:app_product_type_sequence.menu_internal_type_action_stock +#: model:ir.ui.menu,name:app_product_type_sequence.menu_internal_type_action_sys +#: model:ir.ui.view,arch_db:app_product_type_sequence.product_internal_type_form_view +#: model:ir.ui.view,arch_db:app_product_type_sequence.product_internal_type_tree_view +msgid "Product Internal Type" +msgstr "产品内部(编码)类型" + +#. module: app_product_type_sequence +#: model:ir.model,name:app_product_type_sequence.model_product_template +msgid "Product Template" +msgstr "产品模板" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_type +msgid "Product Type" +msgstr "产品类型" + +#. module: app_product_type_sequence +#: code:addons/app_product_type_sequence/models/product_product.py:83 +#, python-format +msgid "Product varient can only create in Product view!" +msgstr "请在产品管理页面增加产品的多属性!" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_route_ids +msgid "Routes" +msgstr "路线" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_sequence_prefix +msgid "Sequence Prefix" +msgstr "编号前缀" + +#. module: app_product_type_sequence +#: code:addons/app_product_type_sequence/models/product_internal_type.py:35 +#: selection:product.internal.type,type:0 +#, python-format +msgid "Service" +msgstr "服务" + +#. module: app_product_type_sequence +#: model:ir.model.fields,help:app_product_type_sequence.field_product_internal_type_sale_ok +msgid "Specify if the product can be selected in a sales order line." +msgstr "如果产品能在销售单明细在被选择,则指定。" + +#. module: app_product_type_sequence +#: code:addons/app_product_type_sequence/models/product_internal_type.py:36 +#: selection:product.internal.type,type:0 +#, python-format +msgid "Stockable Product" +msgstr "可库存产品" + +#. module: app_product_type_sequence +#: sql_constraint:product.internal.type:0 +#: sql_constraint:product.product:0 +msgid "The reference must be unique" +msgstr "产品内部编码不可重复!" + +#. module: app_product_type_sequence +#: model:ir.model.fields,field_description:app_product_type_sequence.field_product_internal_type_ref +msgid "Unique Code" +msgstr "唯一编码" + +#. module: app_product_type_sequence +#: model:ir.model,name:app_product_type_sequence.model_product_internal_type +msgid "product.internal.type" +msgstr "product.internal.type" + diff --git a/app_product_type_sequence/models/__init__.py b/app_product_type_sequence/models/__init__.py new file mode 100644 index 00000000..e312570a --- /dev/null +++ b/app_product_type_sequence/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +import product_template +import product_product +import product_category +import product_internal_type \ No newline at end of file diff --git a/app_product_type_sequence/models/product_category.py b/app_product_type_sequence/models/product_category.py new file mode 100644 index 00000000..841b8f20 --- /dev/null +++ b/app_product_type_sequence/models/product_category.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +# Created on 2017-11-28 +# 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 ProductCategory(models.Model): + _name = "product.category" + _inherit = ['product.category'] + + internal_type = fields.Many2one( + 'product.internal.type', 'Default Internal Type', + auto_join=True, required=False) diff --git a/app_product_type_sequence/models/product_internal_type.py b/app_product_type_sequence/models/product_internal_type.py new file mode 100644 index 00000000..9eaf84de --- /dev/null +++ b/app_product_type_sequence/models/product_internal_type.py @@ -0,0 +1,62 @@ +# -*- 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', translate=True) + description = fields.Char('Description') + 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_ref', + 'unique(ref)', + 'The reference must be unique'), + ] \ No newline at end of file diff --git a/app_product_type_sequence/models/product_product.py b/app_product_type_sequence/models/product_product.py new file mode 100644 index 00000000..99b49892 --- /dev/null +++ b/app_product_type_sequence/models/product_product.py @@ -0,0 +1,84 @@ +# -*- 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=lambda self: _('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) + if sequence: + 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) diff --git a/app_product_type_sequence/models/product_template.py b/app_product_type_sequence/models/product_template.py new file mode 100644 index 00000000..d0d01cca --- /dev/null +++ b/app_product_type_sequence/models/product_template.py @@ -0,0 +1,76 @@ +# -*- 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'] + + # auto_join只要搜索product.template,自动会join。如果经常用到 internal_type 效率会高。 + 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 + + # 当内部类型变化时,改变产品模板的各默认值 + @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: + self.internal_type = self.categ_id.internal_type \ No newline at end of file diff --git a/app_product_type_sequence/security/ir.model.access.csv b/app_product_type_sequence/security/ir.model.access.csv new file mode 100644 index 00000000..02697c29 --- /dev/null +++ b/app_product_type_sequence/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sale_order_type_manager,access_sale_order_type_manager,model_product_internal_type,sales_team.group_sale_manager,1,1,1,1 +access_sale_order_type_salesman,access_sale_order_type_salesman,model_product_internal_type,sales_team.group_sale_salesman,1,0,0,0 diff --git a/app_product_type_sequence/security/security.xml b/app_product_type_sequence/security/security.xml new file mode 100644 index 00000000..c3ab0e2f --- /dev/null +++ b/app_product_type_sequence/security/security.xml @@ -0,0 +1,12 @@ + + + + Product Internal Type multi-company + + ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + + + + + + diff --git a/app_product_type_sequence/static/description/icon.png b/app_product_type_sequence/static/description/icon.png new file mode 100644 index 00000000..2a04f219 Binary files /dev/null and b/app_product_type_sequence/static/description/icon.png differ diff --git a/app_product_type_sequence/static/description/index.html b/app_product_type_sequence/static/description/index.html new file mode 100644 index 00000000..4ac12cc4 --- /dev/null +++ b/app_product_type_sequence/static/description/index.html @@ -0,0 +1,162 @@ +
+
+

App Product Auto Sequence, Auto Code(Variants Supported)

+
+

+ This module allows to associate a sequence to the product reference.
+ The reference (default code) is unique (SQL constraint) and required.
+ Support Product with or without Variants. +

+
    +
  • + Auto Sequence or code for every product. +
  • +
  • + Auto Sequence or for every product variants, like product20171130-001. +
  • +
  • + Product code must be Unique. +
  • +
  • + Define different product type, each product type use own rule of sequence. +
  • +
  • + Quick access in sale , inventory, system menu. +
  • +
  • + Multi language support. +
  • +
+
+ +
+
+ +
+

Sample Rule: if we create on oct 2017

+
    +
  • + Manufactured Products: M20171100001 +
  • +
  • + Components Products: C20171100001 +
  • +
  • + Sourced Products: S20171100001 +
  • +
+

+ Sepcial for variants. add [-00?]
+

    +
  • + Products with color[red]: M20171100001-001 +
  • +
  • + Products with color[blue]: M20171100001-002 +
  • +
  • + Products with color[white]: M20171100001-003 +
  • +
+

+

Installation:

+

+ Prior to installing this module, if you have any existing products you should ensure they already have a + unique reference (or no reference) set.
+ Products with a default_code of '/' or empty will automatically be assigned a code of "!!DP!!" followed + by the system id for that product.
+ Otherwise the setting of the unique constraint will fail and the module will fail to install.
+ + Notice:
+ Odoo product variants is very special.
+ 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.
+ And we make a rule that the product variants can only create after you create normal product template. +

+

How to use: Very simple

+

+ After installed the app. You can Go to anyone of the menu:
+

    +
  • + Sales->Configuration->Products->Product Internal Type +
  • +
  • + Inventory->Configuration->Products->Product Internal Type +
  • +
  • + Settings->Sequences & Identifiers->Product Internal Type +
  • +
+

+

+ You would see the default Product Intertype we create. + +

+ +
+

+

+ And create the product and code by yourself. +

+ +
+

+

+ Notice: The "Sequence Code" Field of sequence must be "product.product" +

+ +
+

+ Go to Prior to installing this module, if you have any existing products you should ensure they already have + a + unique reference (or no reference) set.
+ Products with a default_code of '/' or empty will automatically be assigned a code of "!!DP!!" followed + by the system id for that product.
+ Otherwise the setting of the unique constraint will fail and the module will fail to install.
+ + Notice:
+ Odoo product variants is very special.
+ 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.
+ And we make a rule that the product variants can only create after you create normal product template. +

+
+
+
+ +
+
+ +
+
+
+

Technical Help & Support

+
+
+
+

+ For any type of technical help & support requests, Feel free to contact us

+ + guohuadeng@hotmail.com +

+ Via QQ: 300883

+ + 300883@qq.com +
+
+

+ Visit our website for more support.

+ + http://www.sunpop.cn +
+
+
+
\ No newline at end of file diff --git a/app_product_type_sequence/static/description/set1.jpg b/app_product_type_sequence/static/description/set1.jpg new file mode 100644 index 00000000..77910e22 Binary files /dev/null and b/app_product_type_sequence/static/description/set1.jpg differ diff --git a/app_product_type_sequence/static/description/set2.jpg b/app_product_type_sequence/static/description/set2.jpg new file mode 100644 index 00000000..f05874e3 Binary files /dev/null and b/app_product_type_sequence/static/description/set2.jpg differ diff --git a/app_product_type_sequence/static/description/set3.jpg b/app_product_type_sequence/static/description/set3.jpg new file mode 100644 index 00000000..78c9e415 Binary files /dev/null and b/app_product_type_sequence/static/description/set3.jpg differ diff --git a/app_product_type_sequence/static/description/set4.jpg b/app_product_type_sequence/static/description/set4.jpg new file mode 100644 index 00000000..f2d148cf Binary files /dev/null and b/app_product_type_sequence/static/description/set4.jpg differ diff --git a/app_product_type_sequence/static/description/set5.jpg b/app_product_type_sequence/static/description/set5.jpg new file mode 100644 index 00000000..2d422293 Binary files /dev/null and b/app_product_type_sequence/static/description/set5.jpg differ diff --git a/app_product_type_sequence/tests/__init__.py b/app_product_type_sequence/tests/__init__.py new file mode 100644 index 00000000..269a938e --- /dev/null +++ b/app_product_type_sequence/tests/__init__.py @@ -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 diff --git a/app_product_type_sequence/tests/test_product_sequence.py b/app_product_type_sequence/tests/test_product_sequence.py new file mode 100644 index 00000000..f275be4f --- /dev/null +++ b/app_product_type_sequence/tests/test_product_sequence.py @@ -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,)) diff --git a/app_product_type_sequence/views/product_category_view.xml b/app_product_type_sequence/views/product_category_view.xml new file mode 100644 index 00000000..7e1b5c79 --- /dev/null +++ b/app_product_type_sequence/views/product_category_view.xml @@ -0,0 +1,27 @@ + + + + + + product.category.list.internal_type + product.category + + + + + + + + + + product.category.form._internal_type + product.category + + + + + + + + + diff --git a/app_product_type_sequence/views/product_internal_type_view.xml b/app_product_type_sequence/views/product_internal_type_view.xml new file mode 100644 index 00000000..36107c92 --- /dev/null +++ b/app_product_type_sequence/views/product_internal_type_view.xml @@ -0,0 +1,77 @@ + + + + + + product.internal.type.tree + product.internal.type + + + + + + + + + + + + + + + + + product.internal.type.form + product.internal.type + +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + Product Internal Type + ir.actions.act_window + product.internal.type + tree,form + + + + + + + +
+
diff --git a/app_product_type_sequence/views/product_product_view.xml b/app_product_type_sequence/views/product_product_view.xml new file mode 100644 index 00000000..834bb3ef --- /dev/null +++ b/app_product_type_sequence/views/product_product_view.xml @@ -0,0 +1,16 @@ + + + + + + product.product.tree + product.product + + + + + + + + + diff --git a/app_product_type_sequence/views/product_template_view.xml b/app_product_type_sequence/views/product_template_view.xml new file mode 100644 index 00000000..94a811ad --- /dev/null +++ b/app_product_type_sequence/views/product_template_view.xml @@ -0,0 +1,30 @@ + + + + + + product.template.product.tree + product.template + + + + + + + + + + product.template.common.form + product.template + + + +
+
+
+
+
+
+
diff --git a/app_product_type_sequence/产品自动唯一编码模块支持多规格.txt b/app_product_type_sequence/产品自动唯一编码模块支持多规格.txt new file mode 100644 index 00000000..a62820ce --- /dev/null +++ b/app_product_type_sequence/产品自动唯一编码模块支持多规格.txt @@ -0,0 +1,22 @@ +App Product Auto Sequence, Auto Code(Variants Supported) + +1.ԶƷ롣 +2.ԶƷ룬ʽΪ Ʒ-001 +3.ƷǿҪΨһ +4.ԶƷͣͬƷʹòͬ +5.ۡ桢ϵͳ˵пٶ塣 +6.֧֡ + +This module allows to associate a sequence to the product reference.
+The reference (default code) is unique (SQL constraint) and required.
+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.
֧֡ + + +ҳ棬 +http://www.sunpop.cn/product/app-product-auto-sequence-auto-codevariants-supported/