class AccountTaxTemplatePython(models.Model): _inherit = 'account.tax.template' amount_type = fields.Selection(selection_add=[('code', 'Python Code')]) python_compute = fields.Text( string='Python Code', default="result = price_unit * 0.10", help= "Compute the amount of the tax by setting the variable 'result'.\n\n" ":param base_amount: float, actual amount on which the tax is applied\n" ":param price_unit: float\n" ":param quantity: float\n" ":param product: product.product recordset singleton or None\n" ":param partner: res.partner recordset singleton or None") python_applicable = fields.Text( string='Applicable Code', default="result = True", help= "Determine if the tax will be applied by setting the variable 'result' to True or False.\n\n" ":param price_unit: float\n" ":param quantity: float\n" ":param product: product.product recordset singleton or None\n" ":param partner: res.partner recordset singleton or None") def _get_tax_vals(self, company, tax_template_to_tax): """ This method generates a dictionnary of all the values for the tax that will be created. """ self.ensure_one() res = super(AccountTaxTemplatePython, self)._get_tax_vals(company, tax_template_to_tax) res['python_compute'] = self.python_compute res['python_applicable'] = self.python_applicable return res
class Stage(models.Model): """ Model for case stages. This models the main stages of a document management flow. Main CRM objects (leads, opportunities, project issues, ...) will now use only stages, instead of state and stages. Stages are for example used to display the kanban view of records. """ _name = "crm.stage" _description = "Stage of case" _rec_name = 'name' _order = "sequence, name, id" @api.model def default_get(self, fields): """ Hack : when going from the pipeline, creating a stage with a sales team in context should not create a stage for the current sales channel only """ ctx = dict(self.env.context) if ctx.get('default_team_id') and not ctx.get('crm_team_mono'): ctx.pop('default_team_id') return super(Stage, self.with_context(ctx)).default_get(fields) name = fields.Char('Stage Name', required=True, translate=True) sequence = fields.Integer('Sequence', default=1, help="Used to order stages. Lower is better.") probability = fields.Float( 'Probability (%)', required=True, default=10.0, help= "This percentage depicts the default/average probability of the Case for this stage to be a success" ) on_change = fields.Boolean( 'Change Probability Automatically', help= "Setting this stage will change the probability automatically on the opportunity." ) requirements = fields.Text( 'Requirements', help= "Enter here the internal requirements for this stage (ex: Offer sent to customer). It will appear as a tooltip over the stage's name." ) team_id = fields.Many2one( 'crm.team', string='Team', ondelete='set null', help= 'Specific team that uses this stage. Other teams will not be able to see or use this stage.' ) legend_priority = fields.Text( 'Priority Management Explanation', translate=True, help= 'Explanation text to help users using the star and priority mechanism on stages or issues that are in this stage.' ) fold = fields.Boolean( 'Folded in Pipeline', help= 'This stage is folded in the kanban view when there are no records in that stage to display.' )
class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' gengo_private_key = fields.Text(string="Gengo Private Key", related="company_id.gengo_private_key") gengo_public_key = fields.Text(string="Gengo Public Key", related="company_id.gengo_public_key") gengo_comment = fields.Text(string="Comments", related="company_id.gengo_comment", help="This comment will be automatically be enclosed in each an every request sent to Gengo") gengo_auto_approve = fields.Boolean(string="Auto Approve Translation ?", related="company_id.gengo_auto_approve", help="Jobs are Automatically Approved by Gengo.") gengo_sandbox = fields.Boolean(string="Sandbox Mode", help="Check this box if you're using the sandbox mode of Gengo, mainly used for testing purpose.")
class AccountingAssertTest(models.Model): _name = "accounting.assert.test" _order = "sequence" name = fields.Char(string='Test Name', required=True, index=True, translate=True) desc = fields.Text(string='Test Description', index=True, translate=True) code_exec = fields.Text(string='Python code', required=True, default=CODE_EXEC_DEFAULT) active = fields.Boolean(default=True) sequence = fields.Integer(default=10)
class pos_cache(models.Model): _name = 'pos.cache' cache = fields.Binary(attachment=True) product_domain = fields.Text(required=True) product_fields = fields.Text(required=True) config_id = fields.Many2one('pos.config', ondelete='cascade', required=True) compute_user_id = fields.Many2one('res.users', 'Cache compute user', required=True) @api.model def refresh_all_caches(self): self.env['pos.cache'].search([]).refresh_cache() @api.one def refresh_cache(self): Product = self.env['product.product'].sudo(self.compute_user_id.id) products = Product.search(self.get_product_domain()) prod_ctx = products.with_context( pricelist=self.config_id.pricelist_id.id, display_default_code=False, lang=self.compute_user_id.lang) res = prod_ctx.read(self.get_product_fields()) datas = { 'cache': base64.encodestring(json.dumps(res).encode('utf-8')), } self.write(datas) @api.model def get_product_domain(self): return literal_eval(self.product_domain) @api.model def get_product_fields(self): return literal_eval(self.product_fields) @api.model def get_cache(self, domain, fields): if not self.cache or domain != self.get_product_domain( ) or fields != self.get_product_fields(): self.product_domain = str(domain) self.product_fields = str(fields) self.refresh_cache() return json.loads(base64.decodestring(self.cache).decode('utf-8'))
class grant_badge_wizard(models.TransientModel): """ Wizard allowing to grant a badge to a user""" _name = 'gamification.badge.user.wizard' user_id = fields.Many2one("res.users", string='User', required=True) badge_id = fields.Many2one("gamification.badge", string='Badge', required=True) comment = fields.Text('Comment') @api.multi def action_grant_badge(self): """Wizard action for sending a badge to a chosen user""" BadgeUser = self.env['gamification.badge.user'] uid = self.env.uid for wiz in self: if uid == wiz.user_id.id: raise exceptions.UserError( _('You can not grant a badge to yourself')) #create the badge BadgeUser.create({ 'user_id': wiz.user_id.id, 'sender_id': uid, 'badge_id': wiz.badge_id.id, 'comment': wiz.comment, })._send_badge() return True
class ConverterTest(models.Model): _name = 'web_editor.converter.test' # disable translation export for those brilliant field labels and values _translate = False char = fields.Char() integer = fields.Integer() float = fields.Float() numeric = fields.Float(digits=(16, 2)) many2one = fields.Many2one('web_editor.converter.test.sub') binary = fields.Binary() date = fields.Date() datetime = fields.Datetime() selection = fields.Selection([ (1, "réponse A"), (2, "réponse B"), (3, "réponse C"), (4, "réponse <D>"), ]) selection_str = fields.Selection( [ ('A', "Qu'il n'est pas arrivé à Toronto"), ('B', "Qu'il était supposé arriver à Toronto"), ('C', "Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?"), ('D', "La réponse D"), ], string=u"Lorsqu'un pancake prend l'avion à destination de Toronto et " u"qu'il fait une escale technique à St Claude, on dit:") html = fields.Html() text = fields.Text()
class WebsiteResPartner(models.Model): _name = 'res.partner' _inherit = [ 'res.partner', 'website.seo.metadata', 'website.published.mixin' ] def _default_website(self): default_website_id = self.env.ref('website.default_website') return [default_website_id.id] if default_website_id else None website_description = fields.Html('Website Partner Full Description', strip_style=True) website_short_description = fields.Text( 'Website Partner Short Description') website_ids = fields.Many2many('website', 'website_partner_pub_rel', 'website_id', 'partner_id', string='Websites', copy=False, default=_default_website, help='List of websites in which ' 'Partner will published.') @api.multi def _compute_website_url(self): super(WebsiteResPartner, self)._compute_website_url() for partner in self: partner.website_url = "/partners/%s" % slug(partner)
class MailShortcode(models.Model): """ Shortcode Canned Responses, allowing the user to defined shortcuts in its message. Should be applied before storing message in database. Emoji allowing replacing text with image for visual effect. Should be applied when the message is displayed (only for final rendering). These shortcodes are global and are available for every user. """ _name = 'mail.shortcode' _description = 'Canned Response / Shortcode' source = fields.Char( 'Shortcut', required=True, index=True, help="The shortcut which must be replaced in the Chat Messages") unicode_source = fields.Char( string='Unicode Character', help= "The source is replaced by this unicode character in the Chat Messages" ) substitution = fields.Text( 'Substitution', required=True, index=True, help="The escaped html code replacing the shortcut") description = fields.Char('Description') shortcode_type = fields.Selection([('image', 'Smiley'), ('text', 'Canned Response')], required=True, default='text', help="* Smiley are only used for HTML code to display an image "\ "* Text (default value) is used to substitute text with another text")
class MrpProductionMessage(models.Model): _name = "mrp.message" _description = "Production Message" @api.model def _default_valid_until(self): return datetime.today() + relativedelta(days=7) name = fields.Text(compute='_get_note_first_line', store=True) message = fields.Html(required=True) product_tmpl_id = fields.Many2one('product.template', 'Product Template') product_id = fields.Many2one('product.product', string="Product") bom_id = fields.Many2one('mrp.bom', 'Bill of Material', domain="['|', ('product_id', '=', product_id), ('product_tmpl_id.product_variant_ids','=', product_id)]") workcenter_id = fields.Many2one('mrp.workcenter', string='Work Center') valid_until = fields.Date('Validity Date', default=_default_valid_until, required=True) routing_id = fields.Many2one('mrp.routing', string='Routing') @api.depends('message') def _get_note_first_line(self): for message in self: message.name = (message.message and html2plaintext(message.message) or "").strip().replace('*', '').split("\n")[0] @api.multi def save(self): """ Used in a wizard-like form view, manual save button when in edit mode """ return True
class MrpRouting(models.Model): """ Specifies routings of work centers """ _name = 'mrp.routing' _description = 'Routings' name = fields.Char('Routing Name', required=True) active = fields.Boolean( 'Active', default=True, help="If the active field is set to False, it will allow you to hide the routing without removing it.") code = fields.Char( 'Reference', copy=False, default=lambda self: _('New'), readonly=True) note = fields.Text('Description') operation_ids = fields.One2many( 'mrp.routing.workcenter', 'routing_id', 'Operations', copy=True, oldname='workcenter_lines') location_id = fields.Many2one( 'stock.location', 'Production Location', help="Keep empty if you produce at the location where you find the raw materials. " "Set a location if you produce at a fixed location. This can be a partner location " "if you subcontract the manufacturing operations.") company_id = fields.Many2one( 'res.company', 'Company', default=lambda self: self.env['res.company']._company_default_get('mrp.routing')) @api.model def create(self, vals): if 'code' not in vals or vals['code'] == _('New'): vals['code'] = self.env['ir.sequence'].next_by_code('mrp.routing') or _('New') return super(MrpRouting, self).create(vals)
class test_model(models.Model): _name = 'test_converter.test_model' char = fields.Char() integer = fields.Integer() float = fields.Float() numeric = fields.Float(digits=(16, 2)) many2one = fields.Many2one('test_converter.test_model.sub', group_expand='_gbf_m2o') binary = fields.Binary() date = fields.Date() datetime = fields.Datetime() selection = fields.Selection([ (1, "réponse A"), (2, "réponse B"), (3, "réponse C"), (4, "réponse <D>"), ]) selection_str = fields.Selection([ ('A', u"Qu'il n'est pas arrivé à Toronto"), ('B', u"Qu'il était supposé arriver à Toronto"), ('C', u"Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?"), ('D', u"La réponse D"), ], string=u"Lorsqu'un pancake prend l'avion à destination de Toronto et " u"qu'il fait une escale technique à St Claude, on dit:") html = fields.Html() text = fields.Text() # `base` module does not contains any model that implement the functionality # `group_expand`; test this feature here... @api.model def _gbf_m2o(self, subs, domain, order): sub_ids = subs._search([], order=order, access_rights_uid=SUPERUSER_ID) return subs.browse(sub_ids)
class RMALine(models.Model): _name = "rma.line" _description = "RMA Line" product_id = fields.Many2one('product.product', string='Product') uom_id = fields.Many2one('product.uom', string='UOM') qty_delivered = fields.Float(string='Delivered Quantity') qty_return = fields.Float(string='Return Quantity') rma_id = fields.Many2one('rma.request', string='RMA Request Number') move_line_id = fields.Many2one('stock.move', string='Stock Move') reason_id = fields.Many2one("return.reason", sting='Reason for RMA') remark = fields.Text(sting='Remark') team_id = fields.Many2one('crm.team', 'Team', related='rma_id.team_id') @api.onchange('qty_return') def _onchange_qty_return(self): if not self.rma_id.is_website and self.product_id.tracking != 'none': can_be_return_qty = sum( line.qty_done for line in self.move_line_id.move_line_ids if line.lot_id.warranty_date and line.lot_id.warranty_date >= self.rma_id.date) if self.qty_return > can_be_return_qty: raise UserError( _('You can only return %s quantity for ' 'product %s as its warranty has been ' 'expired.') % (can_be_return_qty, self.product_id.name)) elif self.qty_return > self.qty_delivered: raise UserError( _('Return quantity of %s should not be ' 'greater than ordered quantity.') % (self.product_id.name)) if self.qty_return == 0: raise UserError(_('Return quantity should not be 0.'))
class ResPartner(models.Model): _inherit = 'res.partner' sale_order_count = fields.Integer(compute='_compute_sale_order_count', string='# of Sales Order') sale_order_ids = fields.One2many('sale.order', 'partner_id', 'Sales Order') sale_warn = fields.Selection(WARNING_MESSAGE, 'Sales Order', default='no-message', help=WARNING_HELP, required=True) sale_warn_msg = fields.Text('Message for Sales Order') def _compute_sale_order_count(self): sale_data = self.env['sale.order'].read_group(domain=[ ('partner_id', 'child_of', self.ids) ], fields=['partner_id'], groupby=['partner_id']) # read to keep the child/parent relation while aggregating the read_group result in the loop partner_child_ids = self.read(['child_ids']) mapped_data = dict([(m['partner_id'][0], m['partner_id_count']) for m in sale_data]) for partner in self: # let's obtain the partner id and all its child ids from the read up there item = next(p for p in partner_child_ids if p['id'] == partner.id) partner_ids = [partner.id] + item.get('child_ids') # then we can sum for all the partner's child partner.sale_order_count = sum( mapped_data.get(child, 0) for child in partner_ids)
class FleetVehicleLogServices(models.Model): _name = 'fleet.vehicle.log.services' _inherits = {'fleet.vehicle.cost': 'cost_id'} _description = 'Services for vehicles' @api.model def default_get(self, default_fields): res = super(FleetVehicleLogServices, self).default_get(default_fields) service = self.env.ref('fleet.type_service_service_8', raise_if_not_found=False) res.update({ 'date': fields.Date.context_today(self), 'cost_subtype_id': service and service.id or False, 'cost_type': 'services' }) return res purchaser_id = fields.Many2one('res.partner', 'Purchaser', domain="['|',('customer','=',True),('employee','=',True)]") inv_ref = fields.Char('Invoice Reference') vendor_id = fields.Many2one('res.partner', 'Vendor', domain="[('supplier','=',True)]") # we need to keep this field as a related with store=True because the graph view doesn't support # (1) to address fields from inherited table and (2) fields that aren't stored in database cost_amount = fields.Float(related='cost_id.amount', string='Amount', store=True) notes = fields.Text() cost_id = fields.Many2one('fleet.vehicle.cost', 'Cost', required=True, ondelete='cascade') @api.onchange('vehicle_id') def _onchange_vehicle(self): if self.vehicle_id: self.odometer_unit = self.vehicle_id.odometer_unit self.purchaser_id = self.vehicle_id.driver_id.id
class LunchCashMove(models.Model): """ Two types of cashmoves: payment (credit) or order (debit) """ _name = 'lunch.cashmove' _description = 'lunch cashmove' user_id = fields.Many2one('res.users', 'User', default=lambda self: self.env.uid) date = fields.Date('Date', required=True, default=fields.Date.context_today) amount = fields.Float( 'Amount', required=True, help= 'Can be positive (payment) or negative (order or payment if user wants to get his money back)' ) description = fields.Text('Description', help='Can be an order or a payment') order_id = fields.Many2one('lunch.order.line', 'Order', ondelete='cascade') state = fields.Selection([('order', 'Order'), ('payment', 'Payment')], 'Is an order or a payment', default='payment') @api.multi def name_get(self): return [(cashmove.id, '%s %s' % (_('Lunch Cashmove'), '#%d' % cashmove.id)) for cashmove in self]
class SaleQuoteTemplate(models.Model): _name = "sale.quote.template" _description = "Sale Quotation Template" name = fields.Char('Quotation Template', required=True) website_description = fields.Html('Description', translate=html_translate, sanitize_attributes=False) quote_line = fields.One2many('sale.quote.line', 'quote_id', 'Quotation Template Lines', copy=True) note = fields.Text('Terms and conditions') options = fields.One2many('sale.quote.option', 'template_id', 'Optional Products Lines', copy=True) number_of_days = fields.Integer('Quotation Duration', help='Number of days for the validity date computation of the quotation') require_payment = fields.Selection([ (0, 'Online Signature'), (1, 'Online Payment')], default=0, string='Confirmation Mode', help="Choose how you want to confirm an order to launch the delivery process. You can either " "request a digital signature or an upfront payment. With a digital signature, you can " "request the payment when issuing the invoice.") mail_template_id = fields.Many2one( 'mail.template', 'Confirmation Mail', domain=[('model', '=', 'sale.order')], help="This e-mail template will be sent on confirmation. Leave empty to send nothing.") active = fields.Boolean(default=True, help="If unchecked, it will allow you to hide the quotation template without removing it.") @api.multi def open_template(self): self.ensure_one() return { 'type': 'ir.actions.act_url', 'target': 'self', 'url': '/quote/template/%d' % self.id }
class SeoMetadata(models.AbstractModel): _name = 'website.seo.metadata' _description = 'SEO metadata' website_meta_title = fields.Char("Website meta title", translate=True) website_meta_description = fields.Text("Website meta description", translate=True) website_meta_keywords = fields.Char("Website meta keywords", translate=True)
class MailTestSimple(models.Model): _description = 'Test Simple Chatter Record' _name = 'mail.test.simple' _inherit = ['mail.thread'] name = fields.Char() email_from = fields.Char() description = fields.Text()
class RetrospectiveLines(models.Model): _name = "retrospective.lines" user_id = fields.Many2one("res.users", string="User", readonly=True, required=True, default=lambda self: self.env.user) message = fields.Text(string="Message") retrospective_id = fields.Many2one("retrospective", string="Retrospective")
class Discussion(models.Model): _name = 'test_new_api.discussion' name = fields.Char( string='Title', required=True, help="General description of what this discussion is about.") moderator = fields.Many2one('res.users') categories = fields.Many2many('test_new_api.category', 'test_new_api_discussion_category', 'discussion', 'category') participants = fields.Many2many('res.users') messages = fields.One2many('test_new_api.message', 'discussion') message_concat = fields.Text(string='Message concatenate') important_messages = fields.One2many('test_new_api.message', 'discussion', domain=[('important', '=', True)]) very_important_messages = fields.One2many( 'test_new_api.message', 'discussion', domain=lambda self: self._domain_very_important()) emails = fields.One2many('test_new_api.emailmessage', 'discussion') important_emails = fields.One2many('test_new_api.emailmessage', 'discussion', domain=[('important', '=', True)]) def _domain_very_important(self): """Ensure computed O2M domains work as expected.""" return [("important", "=", True)] @api.onchange('name') def _onchange_name(self): # test onchange modifying one2many field values if self.env.context.get('generate_dummy_message' ) and self.name == '{generate_dummy_message}': # update body of existings messages and emails for message in self.messages: message.body = 'not last dummy message' for message in self.important_messages: message.body = 'not last dummy message' # add new dummy message message_vals = self.messages._add_missing_default_values({ 'body': 'dummy message', 'important': True }) self.messages |= self.messages.new(message_vals) self.important_messages |= self.messages.new(message_vals) @api.onchange('moderator') def _onchange_moderator(self): self.participants |= self.moderator @api.onchange('messages') def _onchange_messages(self): self.message_concat = "\n".join( ["%s:%s" % (m.name, m.body) for m in self.messages])
class BadgeUser(models.Model): """User having received a badge""" _name = 'gamification.badge.user' _description = 'Gamification user badge' _order = "create_date desc" _rec_name = "badge_name" user_id = fields.Many2one('res.users', string="User", required=True, ondelete="cascade", index=True) sender_id = fields.Many2one('res.users', string="Sender", help="The user who has send the badge") badge_id = fields.Many2one('gamification.badge', string='Badge', required=True, ondelete="cascade", index=True) challenge_id = fields.Many2one( 'gamification.challenge', string='Challenge originating', help="If this badge was rewarded through a challenge") comment = fields.Text('Comment') badge_name = fields.Char(related='badge_id.name', string="Badge Name") create_date = fields.Datetime('Created', readonly=True) create_uid = fields.Many2one('res.users', string='Creator', readonly=True) def _send_badge(self): """Send a notification to a user for receiving a badge Does not verify constrains on badge granting. The users are added to the owner_ids (create badge_user if needed) The stats counters are incremented :param ids: list(int) of badge users that will receive the badge """ template = self.env.ref('gamification.email_template_badge_received') for badge_user in self: self.env['mail.thread'].message_post_with_template( template.id, model=badge_user._name, res_id=badge_user.id, composition_mode='mass_mail', partner_ids=badge_user.user_id.partner_id.ids, ) return True @api.model def create(self, vals): self.env['gamification.badge'].browse( vals['badge_id']).check_granting() return super(BadgeUser, self).create(vals)
class IntrastatTransaction(models.Model): _name = 'l10n_be_intrastat.transaction' _rec_name = 'code' code = fields.Char(required=True, readonly=True) description = fields.Text(readonly=True) _sql_constraints = [ ('l10n_be_intrastat_trcodeunique', 'UNIQUE (code)', 'Code must be unique.'), ]
class PortalWizard(models.TransientModel): """ A wizard to manage the creation/removal of portal users. """ _name = 'portal.wizard' _description = 'Portal Access Management' def _default_portal(self): return self.env['res.groups'].search([('is_portal', '=', True)], limit=1) portal_id = fields.Many2one( 'res.groups', domain=[('is_portal', '=', True)], required=True, string='Portal', default=_default_portal, help="The portal that users can be added in or removed from.") user_ids = fields.One2many('portal.wizard.user', 'wizard_id', string='Users') welcome_message = fields.Text( 'Invitation Message', help= "This text is included in the email sent to new users of the portal.") @api.onchange('portal_id') def onchange_portal_id(self): # for each partner, determine corresponding portal.wizard.user records partner_ids = self.env.context.get('active_ids', []) contact_ids = set() user_changes = [] for partner in self.env['res.partner'].sudo().browse(partner_ids): contact_partners = partner.child_ids or [partner] for contact in contact_partners: # make sure that each contact appears at most once in the list if contact.id not in contact_ids: contact_ids.add(contact.id) in_portal = False if contact.user_ids: in_portal = self.portal_id in contact.user_ids[ 0].groups_id user_changes.append((0, 0, { 'partner_id': contact.id, 'email': contact.email, 'in_portal': in_portal, })) self.user_ids = user_changes @api.multi def action_apply(self): self.ensure_one() self.user_ids.action_apply() return {'type': 'ir.actions.act_window_close'}
class RetrospectiveMethod(models.Model): _name = "retrospective.method" _inherit = ['ir.branch.company.mixin', 'mail.thread'] _description = "Retrospective Implementation for Project Scrum" name = fields.Char(string="Method Name", required=True, track_visibility='onchange') description = fields.Text(string="Description", track_visibility='onchange')
class SaleQuoteLine(models.Model): _name = "sale.quote.line" _description = "Quotation Template Lines" _order = 'sequence, id' sequence = fields.Integer('Sequence', help="Gives the sequence order when displaying a list of sale quote lines.", default=10) quote_id = fields.Many2one('sale.quote.template', 'Quotation Template Reference', required=True, ondelete='cascade', index=True) name = fields.Text('Description', required=True, translate=True) product_id = fields.Many2one('product.product', 'Product', domain=[('sale_ok', '=', True)], required=True) layout_category_id = fields.Many2one('sale.layout_category', string='Section') website_description = fields.Html('Line Description', related='product_id.product_tmpl_id.quote_description', translate=html_translate) price_unit = fields.Float('Unit Price', required=True, digits=dp.get_precision('Product Price')) discount = fields.Float('Discount (%)', digits=dp.get_precision('Discount'), default=0.0) product_uom_qty = fields.Float('Quantity', required=True, digits=dp.get_precision('Product UoS'), default=1) product_uom_id = fields.Many2one('product.uom', 'Unit of Measure ', required=True) @api.onchange('product_id') def _onchange_product_id(self): self.ensure_one() if self.product_id: name = self.product_id.name_get()[0][1] if self.product_id.description_sale: name += '\n' + self.product_id.description_sale self.name = name self.price_unit = self.product_id.lst_price self.product_uom_id = self.product_id.uom_id.id self.website_description = self.product_id.quote_description or self.product_id.website_description or '' domain = {'product_uom_id': [('category_id', '=', self.product_id.uom_id.category_id.id)]} return {'domain': domain} @api.onchange('product_uom_id') def _onchange_product_uom(self): if self.product_id and self.product_uom_id: self.price_unit = self.product_id.uom_id._compute_price(self.product_id.lst_price, self.product_uom_id) @api.model def create(self, values): values = self._inject_quote_description(values) return super(SaleQuoteLine, self).create(values) @api.multi def write(self, values): values = self._inject_quote_description(values) return super(SaleQuoteLine, self).write(values) def _inject_quote_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.quote_description or product.website_description or '' return values
class IrModelFieldsAnonymizationMigrationFix(models.Model): _name = 'ir.model.fields.anonymization.migration.fix' _order = "sequence" target_version = fields.Char('Target Version') model_name = fields.Char('Model') field_name = fields.Char('Field') query = fields.Text() query_type = fields.Selection(selection=[('sql', 'sql'), ('python', 'python')], string='Query') sequence = fields.Integer()
class WebsiteTwitterTweet(models.Model): _name = 'website.twitter.tweet' website_id = fields.Many2one('website', string='Website') screen_name = fields.Char(string='Screen Name') tweet = fields.Text(string='Tweets') # Twitter IDs are 64-bit unsigned ints, so we need to store them in # unlimited precision NUMERIC columns, which can be done with a # float field. Used digits=(0,0) to indicate unlimited. # Using VARCHAR would work too but would have sorting problems. tweet_id = fields.Float(string='Tweet ID', digits=(0, 0)) # Twitter
class FleetVehicleLogFuel(models.Model): _name = 'fleet.vehicle.log.fuel' _description = 'Fuel log for vehicles' _inherits = {'fleet.vehicle.cost': 'cost_id'} @api.model def default_get(self, default_fields): res = super(FleetVehicleLogFuel, self).default_get(default_fields) service = self.env.ref('fleet.type_service_refueling', raise_if_not_found=False) res.update({ 'date': fields.Date.context_today(self), 'cost_subtype_id': service and service.id or False, 'cost_type': 'fuel' }) return res liter = fields.Float() price_per_liter = fields.Float() purchaser_id = fields.Many2one('res.partner', 'Purchaser', domain="['|',('customer','=',True),('employee','=',True)]") inv_ref = fields.Char('Invoice Reference', size=64) vendor_id = fields.Many2one('res.partner', 'Vendor', domain="[('supplier','=',True)]") notes = fields.Text() cost_id = fields.Many2one('fleet.vehicle.cost', 'Cost', required=True, ondelete='cascade') # we need to keep this field as a related with store=True because the graph view doesn't support # (1) to address fields from inherited table # (2) fields that aren't stored in database cost_amount = fields.Float(related='cost_id.amount', string='Amount', store=True) @api.onchange('vehicle_id') def _onchange_vehicle(self): if self.vehicle_id: self.odometer_unit = self.vehicle_id.odometer_unit self.purchaser_id = self.vehicle_id.driver_id.id @api.onchange('liter', 'price_per_liter', 'amount') def _onchange_liter_price_amount(self): # need to cast in float because the value receveid from web client maybe an integer (Javascript and JSON do not # make any difference between 3.0 and 3). This cause a problem if you encode, for example, 2 liters at 1.5 per # liter => total is computed as 3.0, then trigger an onchange that recomputes price_per_liter as 3/2=1 (instead # of 3.0/2=1.5) # If there is no change in the result, we return an empty dict to prevent an infinite loop due to the 3 intertwine # onchange. And in order to verify that there is no change in the result, we have to limit the precision of the # computation to 2 decimal liter = float(self.liter) price_per_liter = float(self.price_per_liter) amount = float(self.amount) if liter > 0 and price_per_liter > 0 and round(liter * price_per_liter, 2) != amount: self.amount = round(liter * price_per_liter, 2) elif amount > 0 and liter > 0 and round(amount / liter, 2) != price_per_liter: self.price_per_liter = round(amount / liter, 2) elif amount > 0 and price_per_liter > 0 and round(amount / price_per_liter, 2) != liter: self.liter = round(amount / price_per_liter, 2)
class ResCountry(models.Model): _inherit = 'res.country' street_format = fields.Text( help="Format to use for streets belonging to this country.\n\n" "You can use the python-style string pattern with all the fields of the street " "(for example, use '%(street_name)s, %(street_number)s' if you want to display " "the street name, followed by a comma and the house number)" "\n%(street_name)s: the name of the street" "\n%(street_number)s: the house number" "\n%(street_number2)s: the door number", default='%(street_number)s/%(street_number2)s %(street_name)s', required=True)