class res_company(model.Model): _inherit = 'res.company' # Custom Section def _switch_company_get_companies_from_partner( self, cr, uid, ids, context=None): return self.pool['res.company'].search( cr, uid, [('partner_id', 'in', ids)], context=context) # Fields function Section def _get_logo_topbar(self, cr, uid, ids, _field_name, _args, context=None): result = dict.fromkeys(ids, False) for record in self.browse(cr, uid, ids, context=context): size = (48, 48) result[record.id] = image_resize_image( record.partner_id.image, size) return result # Columns Section _columns = { 'logo_topbar': fields.function( _get_logo_topbar, string="Logo displayed in the switch company menu", type="binary", store={ 'res.company': (lambda s, c, u, i, x: i, ['partner_id'], 10), 'res.partner': (_switch_company_get_companies_from_partner, ['image'], 10), } ), }
class sale_order_line(models.Model): _inherit = "sale.order.line" special_offer_line_id = fields.Many2one( 'website_sale_special_offer.special_offer.line', string='Special offer Line') def _get_price_total(self, field_name, arg): tax_obj = self.env['account.tax'] cur_obj = self.env['res.currency'] res = {} if context is None: context = {} for line in self.browse(ids): price = line.price_unit * (1 - (line.discount or 0.0) / 100.0) taxes = tax_obj.compute_all(line.tax_id, price, line.product_uom_qty, line.product_id, line.order_id.partner_id) cur = line.order_id.pricelist_id.currency_id res[line.id] = cur_obj.round(cur, taxes['total_included']) return res _columns = { 'price_total': old_fields.function(_get_price_total, string='Total', digits_compute=dp.get_precision('Account')), }
class WebsiteProposal(models.Model): _name = 'website_proposal.proposal' _rec_name = 'id' def _get_default_company(self): company_id = self.env['res.users']._get_company(context=context) if not company_id: raise UserError(_('Error!'), _('There is no default company for the current user!')) return company_id def _get_res_name(self, name, args): res = {} for r in self.browse(ids): record = self.env[r.res_model].browse(r.res_id) res[r.id] = record.name return res _columns = { 'res_name': fields.function(_get_res_name, string='Name', type='char'), 'access_token': fields.char('Security Token', required=True, copy=False), 'template_id': fields.many2one('website_proposal.template', 'Quote Template', readonly=True), 'head': fields.text('Html head'), 'page_header': fields.text('Page header'), 'website_description': fields.html('Description'), 'page_footer': fields.text('Page footer'), 'res_model': fields.char('Model', readonly=True, help="The database object this is attached to"), 'res_id': fields.integer('Resource ID', readonly=True, help="The record id this is attached to", select=True), 'sign': fields.binary('Singature'), 'sign_date': fields.datetime('Signing Date'), 'signer': fields.binary('Signer'), 'state': fields.selection([ ('draft', 'Draft'), ('rejected', 'Rejected'), ('done', 'Signed'), ]), 'company_id': fields.many2one('res.company', 'Company'), } _defaults = { 'access_token': lambda self, cr, uid, ctx={}: str(uuid.uuid4()), 'company_id': _get_default_company, 'state': 'draft', } def open_proposal(self): return { 'type': 'ir.actions.act_url', 'target': 'self', 'url': '/website_proposal/%s' % (ids[0]) } def edit_proposal(self): return { 'type': 'ir.actions.act_url', 'target': 'self', 'url': '/website_proposal/%s?enable_editor' % (ids[0]) } def create(self, vals): record = self.env[vals.get('res_model']).browse(vals.get('res_id')) mako = mako_template_env.from_string(tools.ustr(vals.get('website_description'))) website_description = mako.render({'record': record}) website_description = website_description.replace('template-only-', '') vals['website_description'] = website_description new_id = super(WebsiteProposal, self).create(vals) return new_id