From 1a1efe3fce12c3bb1dd47021c895e944638941f4 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Fri, 10 Jun 2016 11:02:11 +0200 Subject: [PATCH] [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. --- addons/website_sale_digital/__init__.py | 1 + addons/website_sale_digital/attachment.py | 8 ++++++ addons/website_sale_digital/demo.xml | 3 ++- addons/website_sale_digital/product.py | 27 +++++++------------ .../views/website_sale_digital_view.xml | 6 ++--- 5 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 addons/website_sale_digital/attachment.py diff --git a/addons/website_sale_digital/__init__.py b/addons/website_sale_digital/__init__.py index dedfc9ab606..38053efe854 100644 --- a/addons/website_sale_digital/__init__.py +++ b/addons/website_sale_digital/__init__.py @@ -1,4 +1,5 @@ # -*- encoding: utf-8 -*- import controllers import product +import attachment import account_invoice diff --git a/addons/website_sale_digital/attachment.py b/addons/website_sale_digital/attachment.py new file mode 100644 index 00000000000..a47d51c081d --- /dev/null +++ b/addons/website_sale_digital/attachment.py @@ -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) diff --git a/addons/website_sale_digital/demo.xml b/addons/website_sale_digital/demo.xml index f0df2124616..67f58c5c313 100644 --- a/addons/website_sale_digital/demo.xml +++ b/addons/website_sale_digital/demo.xml @@ -3,7 +3,7 @@ Alice's Adventures in Wonderland - Lewis Caroll 2 4.50 - digital + service Novel by Lewis Caroll. @@ -16,5 +16,6 @@ product.template + True diff --git a/addons/website_sale_digital/product.py b/addons/website_sale_digital/product.py index 2efc3865065..468ea87d3c8 100644 --- a/addons/website_sale_digital/product.py +++ b/addons/website_sale_digital/product.py @@ -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), } diff --git a/addons/website_sale_digital/views/website_sale_digital_view.xml b/addons/website_sale_digital/views/website_sale_digital_view.xml index de95ef2d30c..8cc8a8cf8c6 100644 --- a/addons/website_sale_digital/views/website_sale_digital_view.xml +++ b/addons/website_sale_digital/views/website_sale_digital_view.xml @@ -6,8 +6,7 @@
-
@@ -20,8 +19,7 @@
-