Skip to content

Commit

Permalink
fix model
Browse files Browse the repository at this point in the history
  • Loading branch information
Az Ad committed Jun 3, 2018
1 parent 118d55d commit 3aba7bb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 55 deletions.
97 changes: 59 additions & 38 deletions runex_webshop_2_0/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,69 @@
_logger = logging.getLogger(__name__)


class Partner(models.Model):
class res_partner(osv.osv):
_inherit = 'res.partner'

def _property_product_pricelist(self):

for partner in self:
lang = request.context.get('lang')
pricelist = self.env['res.lang'].search(
[('code', '=', lang)], limit=1
).pricelist
if not pricelist:
# Fallback if no pricelist found
company = self.env['website'].search([], limit=1).company_id
langs = lang.split('_')
country_code = langs and len(langs) == 2 and langs[1]
companies = (False,) if not company else (False, company.id)
if country_code:
domain = []
# force using euro if country is GB
if country_code == 'GB':
domain += [('currency_id.name', '=', 'EUR')]
else:
domain += [('currency_id.country_ids.code', '=', country_code)]
domain += [
('company_id', 'in', companies),
('type', '=', 'sale'),
('version_id', '!=', False),
]
pricelist = self.env['product.pricelist'].search(
domain, limit=1
)
def _property_product_pricelist(self, cr, uid, ids, name, arg, context=None):
res = {}
for id in ids:
# if id == self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'public_partner')[1]:
if True:
lang = request.context.get('lang')
pricelist = self.pool.get('product.pricelist').browse(cr, uid,
self.pool.get('product.pricelist').search(cr, uid,
[('language_ids.code', '=', lang)], context=context), context=context)
if not pricelist:
raise Warning(_("No pricelist found for your language! Please contact the administrator."))
# Fallback if no pricelist found
company_list = self.pool.get('website').search(cr, uid, [], limit=1)
company = self.pool.get('website').browse(cr, uid, company_list).company_id
langs = lang.split('_')
country_code = langs and len(langs) == 2 and langs[1]
companies = (False,) if not company else (False, company.id)
if country_code:
domain = []
# force using euro if country is GB
if country_code == 'GB':
domain += [('currency_id.name', '=', 'EUR')]
else:
domain += [('currency_id.country_ids.code', '=', country_code)]
domain += [
('company_id', 'in', companies),
('type', '=', 'sale'),
('version_id', '!=', False),
]
pricelist_list = self.pool.get('product.pricelist').search(
cr,uid,domain, context=context,limit=1
)
if pricelist_list:
pricelist = self.pool.get('product.pricelist').browse(cr, uid,pricelist_list ,context=context)
if not pricelist:
raise Warning(_("No pricelist found for your language! Please contact the administrator."))
# else:
# partner = self.pool.get('res.partner').read(cr, uid, id, ['partner_product_pricelist', 'lang', 'commercial_partner_id'], context=context)
# # The compute breaks the commercial fields handling. Check if this partner is it's own commercial partner to account for that.
# if partner['commercial_partner_id'] and partner['commercial_partner_id'][0] != id:
# # Get the pricelist from the commercial partner and move along.
# res[id] = self._property_product_pricelist(cr, uid, [partner['commercial_partner_id'][0]], name, arg, context)[partner['commercial_partner_id'][0]]
# continue
# lang = partner['lang']
# pricelist = self.pool.get('product.pricelist').browse(cr, uid,
# partner['partner_product_pricelist'] and partner['partner_product_pricelist'][0] or [], context=context)
if pricelist:
partner.property_product_pricelist = pricelist

property_product_pricelist = fields.Many2one(
compute='_property_product_pricelist',
relation='product.pricelist',
string="Sale Pricelist",
help="This pricelist will be used, instead of the default one, for sales to the current partner"
)
res[id] = pricelist.id
else:
res[id] = False
return res

_columns = {
'property_product_pricelist': osv_fields.function(
_property_product_pricelist,
type='many2one',
relation='product.pricelist',
domain=[('type', '=', 'sale')],
string="Sale Pricelist",
help="This pricelist will be used, instead of the default one, for sales to the current partner"),
}


class Currency(models.Model):
Expand Down
22 changes: 5 additions & 17 deletions website_crm_campaign_runex/campaign_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,6 @@
</field>
</record>

<!--
<record id="product_public_category_form_view" model="ir.ui.view">
<field name="name">product.public.category.form.inherited.website_crm_campaign_runex</field>
<field name="model">product.public.category</field>
<field name="inherit_id" ref="website_sale.product_public_category_form_view" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="mobile_icon" />
</field>
</field>
</record>
-->

<!--<record id="product_public_category_form_view" model="ir.ui.view">-->
<!--<field name="name">product.public.category.form.inherited.website_crm_campaign_runex</field>-->
Expand Down Expand Up @@ -455,11 +443,11 @@
<!--</xpath>-->
<!--</template>-->

<!--<template id="css_js" inherit_id="website.layout" name="Css Js">-->
<!--<xpath expr="//t[@t-call-assets='website.assets_frontend']" position="after">-->
<!--<link href="/website_crm_campaign_runex/static/src/css/sale_campaign.css" rel="stylesheet" type="text/css" />-->
<!--</xpath>-->
<!--</template>-->
<template id="css_js" inherit_id="website.layout" name="Css Js">
<xpath expr="//t[@t-call-assets='website.assets_frontend']" position="after">
<link href="/website_crm_campaign_runex/static/src/css/sale_campaign.css" rel="stylesheet" type="text/css" />
</xpath>
</template>

<template id="assets_backend" inherit_id="web.assets_backend" name="Inherit Assets Backend">
<xpath expr="." position="inside">
Expand Down

0 comments on commit 3aba7bb

Please sign in to comment.