[IMP] website_sale_digital: downloadable attachment marked by product_downloadable field
This allows the user to continue using the attachment feature, without making it public by default, which was the case in the previous implementation. If you wanted to use the product digital attachments, you were foresaking the standard attachment feature since everything you would attach to the product would then be public and downloadable. The "digital" product type was also removed, because you could very well want to provide downloads for a stockable product, like an online manual or a warranty document, or provide downloads for a service, especially considering digital products are considered service in european laws. The product template and variants stat buttons have also been changed: - The template stat button now only displays the files associated at the template level, instead of showing all the files available accross all variants. - The variant stat button now displays the files associated with it but also with the corresponding template, instead of showing only the files associated with the variant. These new stat buttons are closer to what the customer will see in practice, since the variant level stat button will show the set of files that the customer will be able to download when he has bought that product variant. Previously, the template showed a set of files that was never presented to any customer (since it contained the files from all the variants at once), and the variant was showing less files, since it was ignoring the ones from the template.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
import controllers
|
||||
import product
|
||||
import attachment
|
||||
import account_invoice
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
from openerp import models, fields, api, _
|
||||
|
||||
|
||||
class ir_attachment(models.Model):
|
||||
_inherit = ['ir.attachment']
|
||||
|
||||
product_downloadable = fields.Boolean("Downloadable from product portal", default=False)
|
||||
@@ -3,7 +3,7 @@
|
||||
<field name="name">Alice's Adventures in Wonderland - Lewis Caroll</field>
|
||||
<field name="standard_price">2</field>
|
||||
<field name="list_price">4.50</field>
|
||||
<field name="type">digital</field>
|
||||
<field name="type">service</field>
|
||||
<field name="website_published" eval="True"/>
|
||||
<field name="image" type="base64" file="website_sale_digital/static/digital_product_1.jpg"/>
|
||||
<field name="description">Novel by Lewis Caroll.</field>
|
||||
@@ -16,5 +16,6 @@
|
||||
<field name="datas" type="base64" file="website_sale_digital/static/alice.pdf"/>
|
||||
<field name="res_id" ref="website_sale_digital.product_1"/>
|
||||
<field name="res_model">product.template</field>
|
||||
<field name="product_downloadable">True</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
@@ -11,30 +11,19 @@ class ProductTemplate(models.Model):
|
||||
def _compute_attachment_count(self):
|
||||
IrAttachment = self.env['ir.attachment']
|
||||
for ptemplate in self:
|
||||
prod_tmpl_attach_count = IrAttachment.search_count([('res_model', '=', 'product.template'), ('res_id', 'in', ptemplate.ids)])
|
||||
prod_attach_count = IrAttachment.search_count([('res_model', '=', 'product.product'), ('res_id', 'in', ptemplate.product_variant_ids.ids)])
|
||||
ptemplate.attachment_count = prod_tmpl_attach_count + prod_attach_count
|
||||
|
||||
@api.model
|
||||
def _get_product_template_type(self):
|
||||
res = super(ProductTemplate, self)._get_product_template_type()
|
||||
if 'digital' not in [item[0] for item in res]:
|
||||
res.append(('digital', _('Digital Content')))
|
||||
return res
|
||||
ptemplate.attachment_count = IrAttachment.search_count([('res_model', '=', ptemplate._name), ('res_id', 'in', ptemplate.ids), ('product_downloadable', '=', True)])
|
||||
|
||||
@api.multi
|
||||
def action_open_attachments(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'name': _('Digital Attachments'),
|
||||
'domain': ['|',
|
||||
'&', ('res_model', '=', 'product.product'), ('res_id', 'in', self.product_variant_ids.ids),
|
||||
'&', ('res_model', '=', self._name), ('res_id', '=', self.id)],
|
||||
'domain': [('res_model', '=', self._name), ('res_id', '=', self.id), ('product_downloadable', '=', True)],
|
||||
'res_model': 'ir.attachment',
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_mode': 'kanban,form',
|
||||
'view_type': 'form',
|
||||
'context': "{'default_res_model': '%s','default_res_id': %d}" % (self._name, self.id),
|
||||
'context': "{'default_res_model': '%s','default_res_id': %d, 'default_product_downloadable': True}" % (self._name, self.id),
|
||||
}
|
||||
|
||||
|
||||
@@ -47,17 +36,21 @@ class Product(models.Model):
|
||||
def _compute_attachment_count(self):
|
||||
IrAttachment = self.env['ir.attachment']
|
||||
for product in self:
|
||||
product.attachment_count = IrAttachment.search_count([('res_model', '=', product._name), ('res_id', 'in', product.ids)])
|
||||
prod_tmpl_attach_count = IrAttachment.search_count([('res_model', '=', 'product.template'), ('res_id', 'in', product.product_tmpl_id.ids), ('product_downloadable', '=', True)])
|
||||
prod_attach_count = IrAttachment.search_count([('res_model', '=', 'product.product'), ('res_id', 'in', product.ids), ('product_downloadable', '=', True)])
|
||||
product.attachment_count = prod_tmpl_attach_count + prod_attach_count
|
||||
|
||||
@api.multi
|
||||
def action_open_attachments(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'name': _('Digital Attachments'),
|
||||
'domain': [('res_model', '=', self._name), ('res_id', '=', self.id)],
|
||||
'domain': [('product_downloadable', '=', True), '|',
|
||||
'&', ('res_model', '=', 'product.template'), '&', ('res_id', '=', self.product_tmpl_id.id),
|
||||
'&', ('res_model', '=', self._name), '&', ('res_id', '=', self.id)],
|
||||
'res_model': 'ir.attachment',
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_mode': 'kanban,form',
|
||||
'view_type': 'form',
|
||||
'context': "{'default_res_model': '%s','default_res_id': %d}" % (self._name, self.id),
|
||||
'context': "{'default_res_model': '%s','default_res_id': %d, 'default_product_downloadable': True}" % (self._name, self.id),
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
<field name="inherit_id" ref="product.product_template_only_form_view" />
|
||||
<field name="arch" type="xml">
|
||||
<div name="button_box" position="inside">
|
||||
<button class="oe_stat_button" name="action_open_attachments" type="object"
|
||||
attrs="{'invisible':[('type', '!=', 'digital')]}" icon="fa-file">
|
||||
<button class="oe_stat_button" name="action_open_attachments" type="object" icon="fa-file">
|
||||
<field string="File" name="attachment_count" widget="statinfo" />
|
||||
</button>
|
||||
</div>
|
||||
@@ -20,8 +19,7 @@
|
||||
<field name="inherit_id" ref="product.product_normal_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<div name="button_box" position="inside">
|
||||
<button class="oe_stat_button" name="action_open_attachments" type="object"
|
||||
attrs="{'invisible':[('type', '!=', 'digital')]}" icon="fa-file">
|
||||
<button class="oe_stat_button" name="action_open_attachments" type="object" icon="fa-file">
|
||||
<field string="File" name="attachment_count" widget="statinfo" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user