Browse Source
If the user modify or translate the name of the product "Gift Coupon" the system will be no more able to find it. So, I: 1) Create a field in the sale parameters page (related to a res.company field to be stored) to select the product use in sale order line 2) Use this parameter in the controller 3) Create a migration method for existing database with this module (so just pull the module version on the customer server, restart the server and update the module)pull/120/head
11 changed files with 91 additions and 3 deletions
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2019 Noviat NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
import odoo |
|||
|
|||
|
|||
def update_discount_product_value(env): |
|||
discount_product = env.ref( |
|||
'website_coupon.discount_product') |
|||
discount_product.default_code = 'gift_coupon' |
|||
|
|||
|
|||
def migrate(cr, version): |
|||
if not version: |
|||
# installation of the module |
|||
return |
|||
with odoo.api.Environment.manage(): |
|||
env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) |
|||
update_discount_product_value(env) |
@ -0,0 +1,16 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2019 Noviat NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from odoo import models, fields, api |
|||
|
|||
|
|||
class ResCompany(models.Model): |
|||
_inherit = 'res.company' |
|||
|
|||
gift_coupon_product_id = fields.Many2one( |
|||
comodel_name='product.product', |
|||
string="Gift coupon", |
|||
default=lambda self: self.env['product.product'].search( |
|||
[('default_code', '=', 'gift_coupon')], limit=1), |
|||
) |
@ -0,0 +1,5 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2019 Noviat NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from . import res_config |
@ -0,0 +1,5 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2019 Noviat NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from . import sale_config_settings |
@ -0,0 +1,12 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2019 Noviat NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from odoo import api, fields, models |
|||
|
|||
|
|||
class SaleConfigSettings(models.TransientModel): |
|||
_inherit = 'sale.config.settings' |
|||
|
|||
gift_coupon_product_id = fields.Many2one( |
|||
related='company_id.gift_coupon_product_id', string="Gift coupon") |
@ -0,0 +1,13 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<record id="view_sales_config_inherit_sale" model="ir.ui.view"> |
|||
<field name="name">sale settings</field> |
|||
<field name="model">sale.config.settings</field> |
|||
<field name="inherit_id" ref="sale.view_sales_config"/> |
|||
<field name="arch" type="xml"> |
|||
<field name="deposit_product_id_setting" position="after"> |
|||
<field name="gift_coupon_product_id"/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
</odoo> |
Loading…
Reference in new issue