summaryrefslogtreecommitdiff
path: root/addons/sale_quotation_builder/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/sale_quotation_builder/models
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/sale_quotation_builder/models')
-rw-r--r--addons/sale_quotation_builder/models/__init__.py7
-rw-r--r--addons/sale_quotation_builder/models/product_template.py24
-rw-r--r--addons/sale_quotation_builder/models/res_company.py17
-rw-r--r--addons/sale_quotation_builder/models/sale_order.py78
-rw-r--r--addons/sale_quotation_builder/models/sale_order_template.py61
5 files changed, 187 insertions, 0 deletions
diff --git a/addons/sale_quotation_builder/models/__init__.py b/addons/sale_quotation_builder/models/__init__.py
new file mode 100644
index 00000000..88420748
--- /dev/null
+++ b/addons/sale_quotation_builder/models/__init__.py
@@ -0,0 +1,7 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import product_template
+from . import res_company
+from . import sale_order
+from . import sale_order_template
diff --git a/addons/sale_quotation_builder/models/product_template.py b/addons/sale_quotation_builder/models/product_template.py
new file mode 100644
index 00000000..91a10749
--- /dev/null
+++ b/addons/sale_quotation_builder/models/product_template.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import fields, models, api
+from odoo.tools.translate import html_translate
+
+
+class ProductTemplate(models.Model):
+ _inherit = "product.template"
+
+ quotation_only_description = fields.Html('Quotation Only Description', sanitize_attributes=False,
+ translate=html_translate, help="The quotation description (not used on eCommerce)")
+
+ quotation_description = fields.Html('Quotation Description', compute='_compute_quotation_description',
+ help="This field uses the Quotation Only Description if it is defined, otherwise it will try to read the eCommerce Description.")
+
+ def _compute_quotation_description(self):
+ for record in self:
+ if record.quotation_only_description:
+ record.quotation_description = record.quotation_only_description
+ elif hasattr(record, 'website_description') and record.website_description:
+ record.quotation_description = record.website_description
+ else:
+ record.quotation_description = ''
diff --git a/addons/sale_quotation_builder/models/res_company.py b/addons/sale_quotation_builder/models/res_company.py
new file mode 100644
index 00000000..a6df079e
--- /dev/null
+++ b/addons/sale_quotation_builder/models/res_company.py
@@ -0,0 +1,17 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import models, api
+
+
+class ResCompany(models.Model):
+ _inherit = 'res.company'
+
+ @api.model
+ def _set_default_sale_order_template_id_if_empty(self):
+ template = self.env.ref('sale_quotation_builder.sale_order_template_default', raise_if_not_found=False)
+ if not template:
+ return
+ companies = self.sudo().search([])
+ for company in companies:
+ company.sale_order_template_id = company.sale_order_template_id or template
diff --git a/addons/sale_quotation_builder/models/sale_order.py b/addons/sale_quotation_builder/models/sale_order.py
new file mode 100644
index 00000000..22c88388
--- /dev/null
+++ b/addons/sale_quotation_builder/models/sale_order.py
@@ -0,0 +1,78 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, models
+from odoo.tools.translate import html_translate
+
+
+class SaleOrder(models.Model):
+ _inherit = 'sale.order'
+
+ website_description = fields.Html('Website Description', sanitize_attributes=False, translate=html_translate, sanitize_form=False)
+
+ @api.onchange('partner_id')
+ def onchange_update_description_lang(self):
+ if not self.sale_order_template_id:
+ return
+ else:
+ template = self.sale_order_template_id.with_context(lang=self.partner_id.lang)
+ self.website_description = template.website_description
+
+ def _compute_line_data_for_template_change(self, line):
+ vals = super(SaleOrder, self)._compute_line_data_for_template_change(line)
+ vals.update(website_description=line.website_description)
+ return vals
+
+ def _compute_option_data_for_template_change(self, option):
+ vals = super(SaleOrder, self)._compute_option_data_for_template_change(option)
+ vals.update(website_description=option.website_description)
+ return vals
+
+ @api.onchange('sale_order_template_id')
+ def onchange_sale_order_template_id(self):
+ ret = super(SaleOrder, self).onchange_sale_order_template_id()
+ if self.sale_order_template_id:
+ template = self.sale_order_template_id.with_context(lang=self.partner_id.lang)
+ self.website_description = template.website_description
+ return ret
+
+
+class SaleOrderLine(models.Model):
+ _inherit = "sale.order.line"
+
+ website_description = fields.Html('Website Description', sanitize=False, translate=html_translate, sanitize_form=False)
+
+ @api.model
+ def create(self, values):
+ values = self._inject_quotation_description(values)
+ return super(SaleOrderLine, self).create(values)
+
+ def write(self, values):
+ values = self._inject_quotation_description(values)
+ return super(SaleOrderLine, self).write(values)
+
+ def _inject_quotation_description(self, values):
+ values = dict(values or {})
+ if not values.get('website_description') and values.get('product_id'):
+ product = self.env['product.product'].browse(values['product_id'])
+ values.update(website_description=product.quotation_description)
+ return values
+
+
+class SaleOrderOption(models.Model):
+ _inherit = "sale.order.option"
+
+ website_description = fields.Html('Website Description', sanitize_attributes=False, translate=html_translate)
+
+ @api.onchange('product_id', 'uom_id')
+ def _onchange_product_id(self):
+ ret = super(SaleOrderOption, self)._onchange_product_id()
+ if self.product_id:
+ product = self.product_id.with_context(lang=self.order_id.partner_id.lang)
+ self.website_description = product.quotation_description
+ return ret
+
+ def _get_values_to_add_to_order(self):
+ values = super(SaleOrderOption, self)._get_values_to_add_to_order()
+ values.update(website_description=self.website_description)
+ return values
diff --git a/addons/sale_quotation_builder/models/sale_order_template.py b/addons/sale_quotation_builder/models/sale_order_template.py
new file mode 100644
index 00000000..c7fe6a08
--- /dev/null
+++ b/addons/sale_quotation_builder/models/sale_order_template.py
@@ -0,0 +1,61 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, models
+from odoo.tools.translate import html_translate
+
+
+class SaleOrderTemplate(models.Model):
+ _inherit = "sale.order.template"
+
+ website_description = fields.Html('Website Description', translate=html_translate, sanitize_attributes=False, sanitize_form=False)
+
+ def open_template(self):
+ self.ensure_one()
+ return {
+ 'type': 'ir.actions.act_url',
+ 'target': 'self',
+ 'url': '/sale_quotation_builder/template/%d' % self.id
+ }
+
+
+class SaleOrderTemplateLine(models.Model):
+ _inherit = "sale.order.template.line"
+
+ website_description = fields.Html('Website Description', related='product_id.product_tmpl_id.quotation_only_description', translate=html_translate, readonly=False, sanitize_form=False)
+
+ @api.onchange('product_id')
+ def _onchange_product_id(self):
+ ret = super(SaleOrderTemplateLine, self)._onchange_product_id()
+ if self.product_id:
+ self.website_description = self.product_id.quotation_description
+ return ret
+
+ @api.model
+ def create(self, values):
+ values = self._inject_quotation_description(values)
+ return super(SaleOrderTemplateLine, self).create(values)
+
+ def write(self, values):
+ values = self._inject_quotation_description(values)
+ return super(SaleOrderTemplateLine, self).write(values)
+
+ def _inject_quotation_description(self, values):
+ values = dict(values or {})
+ if not values.get('website_description') and values.get('product_id'):
+ product = self.env['product.product'].browse(values['product_id'])
+ values['website_description'] = product.quotation_description
+ return values
+
+
+class SaleOrderTemplateOption(models.Model):
+ _inherit = "sale.order.template.option"
+
+ website_description = fields.Html('Website Description', translate=html_translate, sanitize_attributes=False)
+
+ @api.onchange('product_id')
+ def _onchange_product_id(self):
+ ret = super(SaleOrderTemplateOption, self)._onchange_product_id()
+ if self.product_id:
+ self.website_description = self.product_id.quotation_description
+ return ret