changeset d6fb1bd8902b in modules/product:default
details: https://hg.tryton.org/modules/product?cmd=changeset;node=d6fb1bd8902b
description:
Allow multiple templates to be added/removed on a category
issue7961
review308201003
diffstat:
CHANGELOG | 2 ++
category.py | 18 ++++++++++++++++++
category.xml | 23 +++++++++++++++++++++++
view/category_form.xml | 3 ++-
view/category_product_form.xml | 8 ++++++++
5 files changed, 53 insertions(+), 1 deletions(-)
diffs (115 lines):
diff -r ec2cb2340c57 -r d6fb1bd8902b CHANGELOG
--- a/CHANGELOG Mon Nov 02 16:01:36 2020 +0100
+++ b/CHANGELOG Mon Nov 23 18:04:57 2020 +0100
@@ -1,3 +1,5 @@
+* Allow multiple templates to be added/removed on a category
+
Version 5.8.0 - 2020-11-02
* Bug fixes (see mercurial logs for details)
* Remove support for Python 3.5
diff -r ec2cb2340c57 -r d6fb1bd8902b category.py
--- a/category.py Mon Nov 02 16:01:36 2020 +0100
+++ b/category.py Mon Nov 23 18:04:57 2020 +0100
@@ -1,6 +1,7 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields, tree
+from trytond.pyson import PYSONEncoder
class Category(tree(separator=' / '), ModelSQL, ModelView):
@@ -13,8 +14,25 @@
childs = fields.One2Many(
'product.category', 'parent', string="Children",
help="Used to add structure below the category.")
+ templates = fields.Many2Many(
+ 'product.template-product.category', 'category', 'template',
+ "Products")
@classmethod
def __setup__(cls):
super(Category, cls).__setup__()
cls._order.insert(0, ('name', 'ASC'))
+ cls._buttons.update({
+ 'add_products': {
+ 'icon': 'tryton-add',
+ },
+ })
+
+ @classmethod
+ @ModelView.button_action('product.act_category_product')
+ def add_products(cls, categories):
+ return {
+ 'res_id': [categories[0].id],
+ 'pyson_domain': PYSONEncoder().encode(
+ [('id', '=', categories[0].id)]),
+ }
diff -r ec2cb2340c57 -r d6fb1bd8902b category.xml
--- a/category.xml Mon Nov 02 16:01:36 2020 +0100
+++ b/category.xml Mon Nov 23 18:04:57 2020 +0100
@@ -19,8 +19,15 @@
<record model="ir.ui.view" id="category_view_form">
<field name="model">product.category</field>
<field name="type">form</field>
+ <field name="priority" eval="10"/>
<field name="name">category_form</field>
</record>
+ <record model="ir.ui.view" id="category_view_form_product">
+ <field name="model">product.category</field>
+ <field name="type">form</field>
+ <field name="priority" eval="20"/>
+ <field name="name">category_product_form</field>
+ </record>
<record model="ir.action.act_window" id="act_category_tree">
<field name="name">Categories</field>
@@ -59,6 +66,22 @@
sequence="10" id="menu_category_list"
action="act_category_list"/>
+ <record model="ir.action.act_window" id="act_category_product">
+ <field name="name">Add products</field>
+ <field name="res_model">product.category</field>
+ </record>
+ <record model="ir.action.act_window.view"
id="act_category_product_view1">
+ <field name="sequence" eval="10"/>
+ <field name="view" ref="category_view_form_product"/>
+ <field name="act_window" ref="act_category_product"/>
+ </record>
+
+ <record model="ir.model.button" id="category_add_products_button">
+ <field name="name">add_products</field>
+ <field name="string">Add products</field>
+ <field name="model" search="[('model', '=', 'product.category')]"/>
+ </record>
+
<record model="ir.model.access" id="access_product_category">
<field name="model" search="[('model', '=', 'product.category')]"/>
<field name="perm_read" eval="True"/>
diff -r ec2cb2340c57 -r d6fb1bd8902b view/category_form.xml
--- a/view/category_form.xml Mon Nov 02 16:01:36 2020 +0100
+++ b/view/category_form.xml Mon Nov 23 18:04:57 2020 +0100
@@ -6,9 +6,10 @@
<field name="name"/>
<label name="parent"/>
<field name="parent"/>
- <group colspan="4" col="-1" id="checkboxes">
+ <group colspan="2" col="-1" id="checkboxes">
<!-- Add here some checkboxes ! -->
</group>
+ <button name="add_products" colspan="2"/>
<notebook colspan="4">
<page string="Children" col="1" id="childs">
<field name="childs"/>
diff -r ec2cb2340c57 -r d6fb1bd8902b view/category_product_form.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/view/category_product_form.xml Mon Nov 23 18:04:57 2020 +0100
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<form col="2">
+ <label name="name"/>
+ <field name="name" readonly="1"/>
+ <field name="templates" colspan="2"/>
+</form>