[IMP] website_sale: allow to show extra field on product page

You can in website's settings, add some extra fields to be shown on the product
page.

E.G. if you want to have the internal code, the barcode, or even a custom field
In case of a binary field, 'Technical documentation' or 'Catalog', you will
have a dowload link.

closes odoo/odoo#55872

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Jeremy Kersten
2020-08-13 13:04:44 +00:00
parent c2bd442034
commit 09cb4533c2
3 changed files with 59 additions and 0 deletions
+17
View File
@@ -48,6 +48,8 @@ class Website(models.Model):
shop_ppg = fields.Integer(default=20, string="Number of products in the grid on the shop")
shop_ppr = fields.Integer(default=4, string="Number of grid columns on the shop")
shop_extra_field_ids = fields.One2many('website.sale.extra.field', 'website_id', string='E-Commerce Extra Fields')
@api.depends('all_pricelist_ids')
def _compute_pricelist_ids(self):
Pricelist = self.env['product.pricelist']
@@ -369,3 +371,18 @@ class Website(models.Model):
suggested_controllers = super(Website, self).get_suggested_controllers()
suggested_controllers.append((_('eCommerce'), url_for('/shop'), 'website_sale'))
return suggested_controllers
class WebsiteSaleExtraField(models.Model):
_name = 'website.sale.extra.field'
_description = 'E-Commerce Extra Info Shown on product page'
_order = 'sequence'
website_id = fields.Many2one('website')
sequence = fields.Integer(default=10)
field_id = fields.Many2one(
'ir.model.fields',
domain=[('model_id.model', '=', 'product.template')]
)
label = fields.Char(related='field_id.field_description')
name = fields.Char(related='field_id.name')
@@ -21,3 +21,5 @@ access_product_image_public,product.image public,model_product_image,,1,0,0,0
access_product_image_publisher,product.image wbesite publisher,model_product_image,website.group_website_publisher,1,1,1,1
access_product_image_sale,product.image sale,model_product_image,sales_team.group_sale_manager,1,1,1,1
access_website_sale_payment_acquirer_onboarding_wizard,access.website.sale.payment.acquirer.onboarding.wizard,model_website_sale_payment_acquirer_onboarding_wizard,base.group_system,1,1,1,0
access_ecom_extra_fields_public,access_ecom_extra_field public,model_website_sale_extra_field,,1,0,0,0
access_ecom_extra_fields_publisher,access_ecom_extra_field publisher,model_website_sale_extra_field,website.group_website_publisher,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
21 access_product_image_publisher product.image wbesite publisher model_product_image website.group_website_publisher 1 1 1 1
22 access_product_image_sale product.image sale model_product_image sales_team.group_sale_manager 1 1 1 1
23 access_website_sale_payment_acquirer_onboarding_wizard access.website.sale.payment.acquirer.onboarding.wizard model_website_sale_payment_acquirer_onboarding_wizard base.group_system 1 1 1 0
24 access_ecom_extra_fields_public access_ecom_extra_field public model_website_sale_extra_field 1 0 0 0
25 access_ecom_extra_fields_publisher access_ecom_extra_field publisher model_website_sale_extra_field website.group_website_publisher 1 1 1 1
+40
View File
@@ -1772,4 +1772,44 @@
</div>
</div>
</template>
<record id="view_website_sale_website_form" model="ir.ui.view">
<field name="name">website_sale.website.form</field>
<field name="model">website</field>
<field name="inherit_id" ref="website.view_website_form"/>
<field name="arch" type="xml">
<xpath expr="//notebook" position="inside">
<page string="Product Page Extra Fields" groups="base.group_no_one">
<field name="shop_extra_field_ids" context="{'default_website_id': active_id}">
<tree editable="bottom">
<field name="sequence" widget="handle"/>
<field name="field_id"/>
</tree>
</field>
</page>
</xpath>
</field>
</record>
<template id="ecom_show_extra_fields" inherit_id="website_sale.product" active="False" customize_show="True" name="Show Extra Fields">
<xpath expr="//div[@id='product_details']" position="inside">
<hr/>
<p class="text-muted">
<t t-foreach='website.shop_extra_field_ids' t-as='field' t-if='product[field.name]'>
<b><t t-esc='field.label'/>: </b>
<t t-if='field.field_id.ttype != "binary"'>
<span t-esc='product[field.name]' t-options="{'widget': field.field_id.ttype}"/>
</t>
<t t-else=''>
<a target='_blank' t-attf-href='/web/content/product.template/#{product.id}/#{field.name}?download=1'>
<i class='fa fa-file'></i>
</a>
</t>
<br/>
</t>
</p>
</xpath>
</template>
</odoo>