[IMP] website_sale: add default sequence to category

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 <fja@odoo.com>
Co-authored-by Sébastien Theys <seb@odoo.com>

closes odoo/odoo#46600

Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
This commit is contained in:
fja-odoo
2020-02-28 16:20:15 +00:00
committed by Sébastien Theys
parent 0280b5fb01
commit 25025a886c
2 changed files with 9 additions and 3 deletions
+8 -2
View File
@@ -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')
+1 -1
View File
@@ -131,7 +131,7 @@
<field name="name"/>
<field name="parent_id"/>
<field name="website_id" options="{'no_create': True}" groups="website.group_multi_website"/>
<field name="sequence"/>
<field name="sequence" groups="base.group_no_one"/>
</group>
</div>
</sheet>