From 25025a886c3095d2fae32bc936e0cbf2080a6236 Mon Sep 17 00:00:00 2001 From: fja-odoo Date: Fri, 28 Feb 2020 16:11:45 +0000 Subject: [PATCH] [IMP] website_sale: add default sequence to category MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New categories will now we added at the end by default. The sequence field is hidden in the form view. It's still possible to order them from the list view. Part of task-2002125 Closes #25535 Co-authored-by fja-odoo Co-authored-by Sébastien Theys closes odoo/odoo#46600 Signed-off-by: Romain Derie --- addons/website_sale/models/product.py | 10 ++++++++-- addons/website_sale/views/product_views.xml | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/website_sale/models/product.py b/addons/website_sale/models/product.py index 6103ad064c5..0f3bc938ebe 100644 --- a/addons/website_sale/models/product.py +++ b/addons/website_sale/models/product.py @@ -135,14 +135,20 @@ class ProductPublicCategory(models.Model): _inherit = ["website.seo.metadata", "website.multi.mixin", 'image.mixin'] _description = "Website Product Category" _parent_store = True - _order = "sequence, name" + _order = "sequence, name, id" + + def _default_sequence(self): + cat = self.search([], limit=1, order="sequence DESC") + if cat: + return cat.sequence + 5 + return 10000 name = fields.Char(required=True, translate=True) parent_id = fields.Many2one('product.public.category', string='Parent Category', index=True, ondelete="cascade") parent_path = fields.Char(index=True) child_id = fields.One2many('product.public.category', 'parent_id', string='Children Categories') parents_and_self = fields.Many2many('product.public.category', compute='_compute_parents_and_self') - sequence = fields.Integer(help="Gives the sequence order when displaying a list of product categories.", index=True) + sequence = fields.Integer(help="Gives the sequence order when displaying a list of product categories.", index=True, default=_default_sequence) website_description = fields.Html('Category Description', sanitize_attributes=False, translate=html_translate) product_tmpl_ids = fields.Many2many('product.template', relation='product_public_category_product_template_rel') diff --git a/addons/website_sale/views/product_views.xml b/addons/website_sale/views/product_views.xml index 30a31aad9f5..adbddf7f243 100644 --- a/addons/website_sale/views/product_views.xml +++ b/addons/website_sale/views/product_views.xml @@ -131,7 +131,7 @@ - +