浏览代码

commit inicial

Rodney Enciso Arias 7 年之前
当前提交
967c537153
共有 7 个文件被更改,包括 323 次插入0 次删除
  1. 3 0
      __init__.py
  2. 二进制
      __init__.pyc
  3. 17 0
      __openerp__.py
  4. 二进制
      product_brand.pyc
  5. 75 0
      product_curve.py
  6. 二进制
      product_curve.pyc
  7. 228 0
      product_curve_view.xml

+ 3 - 0
__init__.py

@@ -0,0 +1,3 @@
+# -*- encoding: utf-8 -*-
+
+from . import product_curve

二进制
__init__.pyc


+ 17 - 0
__openerp__.py

@@ -0,0 +1,17 @@
+# -*- encoding: utf-8 -*-
+
+{
+    'name': 'Product Curve Manager',
+    'version': '1.0',
+    'category': 'Product',
+    'summary': 'Add Curve to products',
+    'author': 'NetAndCo, Akretion, Prisnet Telecommunications SA'
+              ', MONK Software, Odoo Community Association (OCA), Eiru',
+    'license': 'AGPL-3',
+    'depends': ['product'],
+    'data': [
+        'product_curve_view.xml',
+        # 'security/ir.model.access.csv'
+    ],
+    'installable': True,
+}

二进制
product_brand.pyc


+ 75 - 0
product_curve.py

@@ -0,0 +1,75 @@
+# -*- encoding: utf-8 -*-
+
+from openerp import models, fields, api
+
+
+class ProductCurve(models.Model):
+    _name = 'product.curve'
+
+    name = fields.Char('Curve Name', required=True)
+    description = fields.Text('Description', translate=True)
+    # partner_id = fields.Many2one(
+    #     'res.partner',
+    #     string='Partner',
+    #     help='Select a partner for this brand if it exists',
+    #     ondelete='restrict'
+    # )
+    logo = fields.Binary('Logo File')
+    product_ids = fields.One2many(
+        'product.template',
+        'product_curve_id',
+        string='Curve Products',
+    )
+    products_count = fields.Integer(
+        string='Number of products',
+        compute='_get_products_count',
+    )
+
+    @api.one
+    @api.depends('product_ids')
+    def _get_products_count(self):
+        self.products_count = len(self.product_ids)
+
+
+class ProductTemplate(models.Model):
+    _inherit = 'product.template'
+
+    product_curve_id = fields.Many2one(
+        'product.curve',
+        string='Curva',
+        help='Select a curve for this product'
+    )
+
+    @api.multi
+    def name_get(self):
+        res = super(ProductTemplate, self).name_get()
+        res2 = []
+        for name_tuple in res:
+            product = self.browse(name_tuple[0])
+            if not product.product_curve_id:
+                res2.append(name_tuple)
+                continue
+            res2.append((
+                name_tuple[0],
+                u'{} ({})'.format(name_tuple[1], product.product_curve_id.name)
+            ))
+        return res2
+
+
+class ProductProduct(models.Model):
+    _inherit = 'product.product'
+
+    @api.multi
+    def name_get(self):
+        res = super(ProductProduct, self).name_get()
+        res2 = []
+        for name_tuple in res:
+            product = self.browse(name_tuple[0])
+            if not product.product_curve_id:
+                res2.append(name_tuple)
+                continue
+            res2.append((
+                name_tuple[0],
+                u'{} ({})'.format(name_tuple[1], product.product_curve_id.name)
+            ))
+        return res2

二进制
product_curve.pyc


+ 228 - 0
product_curve_view.xml

@@ -0,0 +1,228 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<openerp>
+    <data>
+        <record id="product_curve_search_form_view" model="ir.ui.view">
+            <field name="name">product.curve.search.form</field>
+            <field name="model">product.curve</field>
+            <field name="arch" type="xml">
+                <search string="Product Curve">
+                    <field name="name"/>
+                    <!-- <field name="partner_id"/> -->
+                </search>
+            </field>
+        </record>
+
+        <act_window
+            id="action_open_curve_products"
+            name="Curve Products"
+            res_model="product.template"
+            view_type="form"
+            view_mode="kanban,form,tree"
+            domain="[('product_curve_id', '=', active_id)]"/>
+
+        <act_window
+            id="action_open_single_product_curve"
+            name="Product Curve"
+            res_model="product.curve"
+            view_type="form"
+            view_mode="kanban,form,tree"
+            target="current"
+            domain="[('product_ids', 'in', active_id)]"/>
+
+        <record id="view_product_curve_form" model="ir.ui.view">
+            <field name="name">product.curve.form</field>
+            <field name="model">product.curve</field>
+            <field name="arch" type="xml">
+                <form string="Product Curve" version="7.0">
+                    <sheet>
+                        <field name="logo" widget="image" class="oe_avatar oe_left"/>
+                        <div class="oe_title">
+                            <div class="oe_edit_only">
+                                <label for="name" string="Curve Name"/>
+                            </div>
+                            <h1>
+                                <field name="name"/>
+                            </h1>
+                        </div>
+                        <div class="oe_right oe_button_box">
+                            <button
+                                class="oe_inline oe_stat_button"
+                                type="action"
+                                name="%(action_open_curve_products)d"
+                                icon="fa-cubes">
+                                <field name="products_count" string="Products" widget="statinfo" />
+                            </button>
+                        </div>
+                        <!-- <group>
+                            <field name="partner_id"/>
+                        </group> -->
+                        <group string="Description">
+                            <field name="description" nolabel="1"/>
+                        </group>
+                    </sheet>
+                </form>
+            </field>
+        </record>
+
+        <record id="view_product_curve_tree" model="ir.ui.view">
+            <field name="name">product.curve.tree</field>
+            <field name="model">product.curve</field>
+            <field name="arch" type="xml">
+                <tree string="product.curve">
+                    <field name="name"/>
+                    <field name="description"/>
+                    <!-- <field name="partner_id"/> -->
+                </tree>
+            </field>
+        </record>
+
+        <record id="view_product_curve_kanban" model="ir.ui.view">
+            <field name="name">product.curve.kanban</field>
+            <field name="model">product.curve</field>
+            <field name="arch" type="xml">
+                <kanban>
+                    <field name="logo"/>
+                    <field name="products_count"/>
+                    <field name="description"/>
+                    <templates>
+                        <t t-name="kanban-box">
+                            <div class="oe_kanban_vignette oe_semantic_html_override">
+                                <a type="open">
+                                    <img t-att-src="kanban_image('product.product', 'logo', record.id.value)"
+                                         class="oe_kanban_image"/>
+                                </a>
+                                <div class="oe_kanban_details">
+                                    <h4>
+                                        <a type="open">
+                                            <field name="name"/>
+                                        </a>
+                                    </h4>
+                                    <div>
+                                        <a name="%(product_curve.action_open_curve_products)d"
+                                           type="action">
+                                            <t t-esc="record.products_count.value"/> Products
+                                        </a>
+                                    </div>
+                                    <span>
+                                        <t t-esc="record.description.value.substr(0,200)"/>
+                                        <t t-if="record.description.value.length > 200">
+                                            <a type="open"><b>...</b></a>
+                                        </t>
+                                    </span>
+                                </div>
+                            </div>
+                        </t>
+                    </templates>
+                </kanban>
+            </field>
+        </record>
+
+        <record id="product_search_form_view" model="ir.ui.view">
+            <field name="name">product.search.form</field>
+            <field name="model">product.product</field>
+            <field name="inherit_id" ref="product.product_search_form_view"/>
+            <field name="arch" type="xml">
+                <field name="categ_id" position="after">
+                    <field name="product_curve_id"/>
+                </field>
+                <group string='Group by...' position="inside">
+                    <filter string="Curve" name="groupby_curve" domain="[]"
+                            context="{'group_by' : 'product_curve_id'}"/>
+                </group>
+            </field>
+        </record>
+
+        <record id="view_product_template_search_curve" model="ir.ui.view">
+            <field name="name">product.template.search.curve</field>
+            <field name="model">product.template</field>
+            <field name="inherit_id" ref="product.product_template_search_view"/>
+            <field name="arch" type="xml">
+                <field name="name" position="after">
+                    <field name="product_curve_id"/>
+                </field>
+                <group string='Group by...' position="inside">
+                    <filter string="Curva" name="groupby_curve" domain="[]"
+                            context="{'group_by' : 'product_curve_id'}"/>
+                </group>
+            </field>
+        </record>
+
+        <record id="product_template_form_curve_add" model="ir.ui.view">
+            <field name="name">product.template.product.form</field>
+            <field name="model">product.template</field>
+            <field name="inherit_id" ref="product.product_template_form_view" />
+            <field name="arch" type="xml">
+                <field name="name" position="after"  >
+                    <field name="product_curve_id" placeholder="Curve"/>
+                </field>
+            </field>
+        </record>
+
+        <record id="view_product_template_kanban_curve" model="ir.ui.view">
+            <field name="name">product kanban view: add curve</field>
+            <field name="model">product.template</field>
+            <field name="inherit_id" ref="product.product_template_kanban_view" />
+            <field name="arch" type="xml">
+                <xpath expr="//h4" position="after">
+                    <div>
+                        <a t-if="record.product_curve_id" type="action"
+                           name="%(action_open_single_product_curve)d">
+                            <field name="product_curve_id"/>
+                        </a>
+                    </div>
+                </xpath>
+            </field>
+        </record>
+
+        <record id="view_product_variant_kanban_curve" model="ir.ui.view">
+            <field name="name">product variant kanban view: add curve</field>
+            <field name="model">product.product</field>
+            <field name="inherit_id" ref="product.product_kanban_view" />
+            <field name="arch" type="xml">
+                <xpath expr="//h4" position="after">
+                    <div>
+                        <a t-if="record.product_curve_id" type="open">
+                            <field name="product_curve_id"/>
+                        </a>
+                    </div>
+                </xpath>
+            </field>
+        </record>
+
+        <record id="view_product_template_tree_curve" model="ir.ui.view">
+            <field name="name">product tree view: add curve</field>
+            <field name="model">product.template</field>
+            <field name="inherit_id" ref="product.product_template_tree_view" />
+            <field name="arch" type="xml">
+                <field name="name" position="after">
+                    <field name="product_curve_id"/>
+                </field>
+            </field>
+        </record>
+
+        <record id="view_product_variant_tree_curve" model="ir.ui.view">
+            <field name="name">product variant tree view: add curve</field>
+            <field name="model">product.product</field>
+            <field name="inherit_id" ref="product.product_product_tree_view" />
+            <field name="arch" type="xml">
+                <field name="name" position="after">
+                    <field name="product_curve_id"/>
+                </field>
+            </field>
+        </record>
+
+        <record model="ir.actions.act_window" id="action_product_curve">
+            <field name="name">Curva</field>
+            <field name="res_model">product.curve</field>
+            <field name="view_type">form</field>
+            <field name="view_mode">kanban,form,tree</field>
+        </record>
+
+        <menuitem
+            name="Curva de productos"
+            id="menu_product_curve"
+            action="action_product_curve"
+            parent="base.menu_product"/>
+    </data>
+</openerp>