class ProductCategory(models.Model): _inherit = 'product.category' route_ids = fields.Many2many('stock.location.route', 'stock_location_route_categ', 'categ_id', 'route_id', 'Routes', domain=[('product_categ_selectable', '=', True)]) removal_strategy_id = fields.Many2one( 'product.removal', 'Force Removal Strategy', help= "Set a specific removal strategy that will be used regardless of the source location for this product category" ) total_route_ids = fields.Many2many('stock.location.route', string='Total routes', compute='_compute_total_route_ids', readonly=True) @api.one def _compute_total_route_ids(self): category = self routes = self.route_ids while category.parent_id: category = category.parent_id routes |= category.route_ids self.total_route_ids = routes
class BaseModuleUninstall(models.TransientModel): _name = "base.module.uninstall" _description = "Module Uninstall" show_all = fields.Boolean() module_id = fields.Many2one( 'ir.module.module', string="Module", required=True, domain=[('state', 'in', ['installed', 'to upgrade', 'to install'])], ondelete='cascade', readonly=True, ) module_ids = fields.Many2many('ir.module.module', string="Impacted modules", compute='_compute_module_ids') model_ids = fields.Many2many('ir.model', string="Impacted data models", compute='_compute_model_ids') def _get_modules(self): """ Return all the modules impacted by self. """ return self.module_id.downstream_dependencies(self.module_id) @api.depends('module_id', 'show_all') def _compute_module_ids(self): for wizard in self: modules = wizard._get_modules() wizard.module_ids = modules if wizard.show_all else modules.filtered('application') def _get_models(self): """ Return the models (ir.model) to consider for the impact. """ return self.env['ir.model'].search([('transient', '=', False)]) @api.depends('module_ids') def _compute_model_ids(self): ir_models = self._get_models() ir_models_xids = ir_models._get_external_ids() for wizard in self: if wizard.module_id: module_names = set(wizard._get_modules().mapped('name')) def lost(model): xids = ir_models_xids.get(model.id, ()) return xids and all(xid.split('.')[0] in module_names for xid in xids) # find the models that have all their XIDs in the given modules self.model_ids = ir_models.filtered(lost).sorted('name') @api.onchange('module_id') def _onchange_module_id(self): # if we select a technical module, show technical modules by default if not self.module_id.application: self.show_all = True @api.multi def action_uninstall(self): modules = self.mapped('module_id') return modules.button_immediate_uninstall()
class TemplatePreview(models.TransientModel): _inherit = "mail.template" _name = "email_template.preview" _description = "Email Template Preview" @api.model def _get_records(self): """ Return Records of particular Email Template's Model """ template_id = self._context.get('template_id') default_res_id = self._context.get('default_res_id') if not template_id: return [] template = self.env['mail.template'].browse(int(template_id)) records = self.env[template.model_id.model].search([], order="id desc", limit=10) records |= records.browse(default_res_id) return records.name_get() @api.model def default_get(self, fields): result = super(TemplatePreview, self).default_get(fields) if 'res_id' in fields and not result.get('res_id'): records = self._get_records() result['res_id'] = records and records[0][ 0] or False # select first record as a Default if self._context.get( 'template_id' ) and 'model_id' in fields and not result.get('model_id'): result['model_id'] = self.env['mail.template'].browse( self._context['template_id']).model_id.id return result res_id = fields.Selection(_get_records, 'Sample Document') partner_ids = fields.Many2many('res.partner', string='Recipients') attachment_ids = fields.Many2many(string='Attachments', store=False) @api.onchange('res_id') @api.multi def on_change_res_id(self): if not self.res_id: return {} mail_values = {} if self._context.get('template_id'): template = self.env['mail.template'].browse( self._context['template_id']) self.name = template.name mail_values = template.generate_email(self.res_id) for field in [ 'email_from', 'email_to', 'email_cc', 'reply_to', 'subject', 'body_html', 'partner_to', 'partner_ids', 'attachment_ids' ]: setattr(self, field, mail_values.get(field, False))
class Route(models.Model): _name = 'stock.location.route' _description = "Inventory Routes" _order = 'sequence' name = fields.Char('Route', required=True, translate=True) active = fields.Boolean('Active', default=True, help="If the active field is set to False, it will allow you to hide the route without removing it.") sequence = fields.Integer('Sequence', default=0) rule_ids = fields.One2many('stock.rule', 'route_id', 'Rules', copy=True) product_selectable = fields.Boolean('Applicable on Product', default=True, help="When checked, the route will be selectable in the Inventory tab of the Product form.") product_categ_selectable = fields.Boolean('Applicable on Product Category', help="When checked, the route will be selectable on the Product Category.") warehouse_selectable = fields.Boolean('Applicable on Warehouse', help="When a warehouse is selected for this route, this route should be seen as the default route when products pass through this warehouse.") supplied_wh_id = fields.Many2one('stock.warehouse', 'Supplied Warehouse') supplier_wh_id = fields.Many2one('stock.warehouse', 'Supplying Warehouse') company_id = fields.Many2one( 'res.company', 'Company', default=lambda self: self.env['res.company']._company_default_get('stock.location.route'), index=True, help='Leave this field empty if this route is shared between all companies') product_ids = fields.Many2many('product.template', 'stock_route_product', 'route_id', 'product_id', 'Products', copy=False) categ_ids = fields.Many2many('product.category', 'stock_location_route_categ', 'route_id', 'categ_id', 'Product Categories', copy=False) warehouse_ids = fields.Many2many('stock.warehouse', 'stock_route_warehouse', 'route_id', 'warehouse_id', 'Warehouses', copy=False) @api.onchange('warehouse_selectable') def _onchange_warehouse_selectable(self): if not self.warehouse_selectable: self.warehouse_ids = [(5, 0, 0)] def toggle_active(self): for route in self: route.with_context(active_test=False).rule_ids.filtered(lambda ru: ru.active == route.active).toggle_active() super(Route, self).toggle_active() def view_product_ids(self): return { 'name': _('Products'), 'view_type': 'form', 'view_mode': 'tree,form', 'res_model': 'product.template', 'type': 'ir.actions.act_window', 'domain': [('route_ids', 'in', self.ids)], } def view_categ_ids(self): return { 'name': _('Product Categories'), 'view_type': 'form', 'view_mode': 'tree,form', 'res_model': 'product.category', 'type': 'ir.actions.act_window', 'domain': [('route_ids', 'in', self.ids)], }
class HolidaysSummaryDept(models.TransientModel): _name = 'hr.holidays.summary.dept' _description = 'HR Leaves Summary Report By Department' date_from = fields.Date(string='From', required=True, default=lambda *a: time.strftime('%Y-%m-01')) depts = fields.Many2many('hr.department', 'summary_dept_rel', 'sum_id', 'dept_id', string='Department(s)') holiday_type = fields.Selection([('Approved', 'Approved'), ('Confirmed', 'Confirmed'), ('both', 'Both Approved and Confirmed')], string='Leave Type', required=True, default='Approved') @api.multi def print_report(self): self.ensure_one() [data] = self.read() if not data.get('depts'): raise UserError(_('You have to select at least one department.')) departments = self.env['hr.department'].browse(data['depts']) datas = {'ids': [], 'model': 'hr.department', 'form': data} return self.env.ref( 'hr_holidays.action_report_holidayssummary').with_context( from_transient_model=True).report_action(departments, data=datas)
class BaseLanguageInstall(models.TransientModel): _inherit = "base.language.install" website_ids = fields.Many2many('website', string='Websites to translate') @api.model def default_get(self, fields): defaults = super(BaseLanguageInstall, self).default_get(fields) website_id = self._context.get('params', {}).get('website_id') if website_id: if 'website_ids' not in defaults: defaults['website_ids'] = [] defaults['website_ids'].append(website_id) return defaults @api.multi def lang_install(self): action = super(BaseLanguageInstall, self).lang_install() lang = self.env['res.lang'].search([('code', '=', self.lang)], limit=1) if self.website_ids and lang: self.website_ids.write({'language_ids': [(4, lang.id)]}) params = self._context.get('params', {}) if 'url_return' in params: return { 'url': params['url_return'].replace('[lang]', self.lang), 'type': 'ir.actions.act_url', 'target': 'self' } return action
class MassMailingListMerge(models.TransientModel): _name = 'mass.mailing.list.merge' _description = 'Merge Mass Mailing List' src_list_ids = fields.Many2many('mail.mass_mailing.list', string='Mailing Lists') dest_list_id = fields.Many2one('mail.mass_mailing.list', string='Destination Mailing List') merge_options = fields.Selection([ ('new', 'Merge into a new mailing list'), ('existing', 'Merge into an existing mailing list'), ], 'Merge Option', required=True, default='new') new_list_name = fields.Char('New Mailing List Name') archive_src_lists = fields.Boolean('Archive source mailing lists', default=True) @api.model def default_get(self, fields): res = super(MassMailingListMerge, self).default_get(fields) src_list_ids = self.env.context.get('active_ids') res.update({ 'src_list_ids': src_list_ids, 'dest_list_id': src_list_ids and src_list_ids[0] or False, }) return res @api.multi def action_mailing_lists_merge(self): if self.merge_options == 'new': self.dest_list_id = self.env['mail.mass_mailing.list'].create({ 'name': self.new_list_name, }).id self.dest_list_id.action_merge(self.src_list_ids, self.archive_src_lists) return self.dest_list_id
class StockImmediateTransfer(models.TransientModel): _name = 'stock.immediate.transfer' _description = 'Immediate Transfer' pick_ids = fields.Many2many('stock.picking', 'stock_picking_transfer_rel') def process(self): pick_to_backorder = self.env['stock.picking'] pick_to_do = self.env['stock.picking'] for picking in self.pick_ids: # If still in draft => confirm and assign if picking.state == 'draft': picking.action_confirm() if picking.state != 'assigned': picking.action_assign() if picking.state != 'assigned': raise UserError( _("Could not reserve all requested products. Please use the \'Mark as Todo\' button to handle the reservation manually." )) for move in picking.move_lines.filtered( lambda m: m.state not in ['done', 'cancel']): for move_line in move.move_line_ids: move_line.qty_done = move_line.product_uom_qty if picking._check_backorder(): pick_to_backorder |= picking continue pick_to_do |= picking # Process every picking that do not require a backorder, then return a single backorder wizard for every other ones. if pick_to_do: pick_to_do.action_done() if pick_to_backorder: return pick_to_backorder.action_generate_backorder_wizard() return False
class FleetVehicleModel(models.Model): _name = 'fleet.vehicle.model' _description = 'Model of a vehicle' _order = 'name asc' name = fields.Char('Model name', required=True) brand_id = fields.Many2one('fleet.vehicle.model.brand', 'Make', required=True, help='Make of the vehicle') vendors = fields.Many2many('res.partner', 'fleet_vehicle_model_vendors', 'model_id', 'partner_id', string='Vendors') image = fields.Binary(related='brand_id.image', string="Logo", readonly=False) image_medium = fields.Binary(related='brand_id.image_medium', string="Logo (medium)", readonly=False) image_small = fields.Binary(related='brand_id.image_small', string="Logo (small)", readonly=False) @api.multi @api.depends('name', 'brand_id') def name_get(self): res = [] for record in self: name = record.name if record.brand_id.name: name = record.brand_id.name + '/' + name res.append((record.id, name)) return res @api.onchange('brand_id') def _onchange_brand(self): if self.brand_id: self.image_medium = self.brand_id.image else: self.image_medium = False
class StockBackorderConfirmation(models.TransientModel): _name = 'stock.backorder.confirmation' _description = 'Backorder Confirmation' pick_ids = fields.Many2many('stock.picking', 'stock_picking_backorder_rel') @api.one def _process(self, cancel_backorder=False): if cancel_backorder: for pick_id in self.pick_ids: moves_to_log = {} for move in pick_id.move_lines: if float_compare( move.product_uom_qty, move.quantity_done, precision_rounding=move.product_uom.rounding) > 0: moves_to_log[move] = (move.quantity_done, move.product_uom_qty) pick_id._log_less_quantities_than_expected(moves_to_log) self.pick_ids.action_done() if cancel_backorder: for pick_id in self.pick_ids: backorder_pick = self.env['stock.picking'].search([ ('backorder_id', '=', pick_id.id) ]) backorder_pick.action_cancel() pick_id.message_post( body=_("Back order <em>%s</em> <b>cancelled</b>.") % (",".join([b.name or '' for b in backorder_pick]))) def process(self): self._process() def process_cancel_backorder(self): self._process(cancel_backorder=True)
class HolidaysSummaryEmployee(models.TransientModel): _name = 'hr.holidays.summary.employee' _description = 'HR Leaves Summary Report By Employee' date_from = fields.Date(string='From', required=True, default=lambda *a: time.strftime('%Y-%m-01')) emp = fields.Many2many('hr.employee', 'summary_emp_rel', 'sum_id', 'emp_id', string='Employee(s)') holiday_type = fields.Selection([('Approved', 'Approved'), ('Confirmed', 'Confirmed'), ('both', 'Both Approved and Confirmed')], string='Select Leave Type', required=True, default='Approved') @api.multi def print_report(self): self.ensure_one() [data] = self.read() data['emp'] = self.env.context.get('active_ids', []) employees = self.env['hr.employee'].browse(data['emp']) datas = {'ids': [], 'model': 'hr.employee', 'form': data} return self.env.ref( 'hr_holidays.action_report_holidayssummary').report_action( employees, data=datas)
class HrPayslipEmployees(models.TransientModel): _name = 'hr.payslip.employees' _description = 'Generate payslips for all selected employees' employee_ids = fields.Many2many('hr.employee', 'hr_employee_group_rel', 'payslip_id', 'employee_id', 'Employees') @api.multi def compute_sheet(self): payslips = self.env['hr.payslip'] [data] = self.read() active_id = self.env.context.get('active_id') if active_id: [run_data] = self.env['hr.payslip.run'].browse(active_id).read(['date_start', 'date_end', 'credit_note']) from_date = run_data.get('date_start') to_date = run_data.get('date_end') if not data['employee_ids']: raise UserError(_("You must select employee(s) to generate payslip(s).")) for employee in self.env['hr.employee'].browse(data['employee_ids']): slip_data = self.env['hr.payslip'].onchange_employee_id(from_date, to_date, employee.id, contract_id=False) res = { 'employee_id': employee.id, 'name': slip_data['value'].get('name'), 'struct_id': slip_data['value'].get('struct_id'), 'contract_id': slip_data['value'].get('contract_id'), 'payslip_run_id': active_id, 'input_line_ids': [(0, 0, x) for x in slip_data['value'].get('input_line_ids')], 'worked_days_line_ids': [(0, 0, x) for x in slip_data['value'].get('worked_days_line_ids')], 'date_from': from_date, 'date_to': to_date, 'credit_note': run_data.get('credit_note'), 'company_id': employee.company_id.id, } payslips += self.env['hr.payslip'].create(res) payslips.compute_sheet() return {'type': 'ir.actions.act_window_close'}
class MaintenanceTeam(models.Model): _name = 'maintenance.team' _description = 'Maintenance Teams' name = fields.Char(required=True, translate=True) active = fields.Boolean(default=True) company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.user.company_id) member_ids = fields.Many2many('res.users', 'maintenance_team_users_rel', string="Team Members") color = fields.Integer("Color Index", default=0) request_ids = fields.One2many('maintenance.request', 'maintenance_team_id', copy=False) equipment_ids = fields.One2many('maintenance.equipment', 'maintenance_team_id', copy=False) # For the dashboard only todo_request_ids = fields.One2many('maintenance.request', string="Requests", copy=False, compute='_compute_todo_requests') todo_request_count = fields.Integer(string="Number of Requests", compute='_compute_todo_requests') todo_request_count_date = fields.Integer(string="Number of Requests Scheduled", compute='_compute_todo_requests') todo_request_count_high_priority = fields.Integer(string="Number of Requests in High Priority", compute='_compute_todo_requests') todo_request_count_block = fields.Integer(string="Number of Requests Blocked", compute='_compute_todo_requests') todo_request_count_unscheduled = fields.Integer(string="Number of Requests Unscheduled", compute='_compute_todo_requests') @api.one @api.depends('request_ids.stage_id.done') def _compute_todo_requests(self): self.todo_request_ids = self.request_ids.filtered(lambda e: e.stage_id.done==False) self.todo_request_count = len(self.todo_request_ids) self.todo_request_count_date = len(self.todo_request_ids.filtered(lambda e: e.schedule_date != False)) self.todo_request_count_high_priority = len(self.todo_request_ids.filtered(lambda e: e.priority == '3')) self.todo_request_count_block = len(self.todo_request_ids.filtered(lambda e: e.kanban_state == 'blocked')) self.todo_request_count_unscheduled = len(self.todo_request_ids.filtered(lambda e: not e.schedule_date)) @api.one @api.depends('equipment_ids') def _compute_equipment(self): self.equipment_count = len(self.equipment_ids)
class Channel(models.Model): _inherit = 'mail.channel' subscription_department_ids = fields.Many2many( 'hr.department', string='HR Departments', help= 'Automatically subscribe members of those departments to the channel.') def _subscribe_users(self): """ Auto-subscribe members of a department to a channel """ super(Channel, self)._subscribe_users() for mail_channel in self: if mail_channel.subscription_department_ids: mail_channel.write({ 'channel_partner_ids': [(4, partner_id) for partner_id in mail_channel.mapped( 'subscription_department_ids.member_ids.user_id.partner_id' ).ids] }) def write(self, vals): res = super(Channel, self).write(vals) if vals.get('subscription_department_ids'): self._subscribe_users() return res
class ProductionLot(models.Model): _inherit = 'stock.production.lot' sale_order_ids = fields.Many2many('sale.order', string="Sales Orders", compute='_compute_sale_order_ids') sale_order_count = fields.Integer('Sale order count', compute='_compute_sale_order_ids') @api.depends('name') def _compute_sale_order_ids(self): for lot in self: stock_moves = self.env['stock.move.line'].search([ ('lot_id', '=', lot.id), ('state', '=', 'done') ]).mapped('move_id') stock_moves = stock_moves.search([ ('id', 'in', stock_moves.ids) ]).filtered(lambda move: move.picking_id.location_dest_id.usage == 'customer' and move.state == 'done') lot.sale_order_ids = stock_moves.mapped('sale_line_id.order_id') lot.sale_order_count = len(lot.sale_order_ids) def action_view_so(self): self.ensure_one() action = self.env.ref('sale.action_orders').read()[0] action['domain'] = [('id', 'in', self.mapped('sale_order_ids.id'))] return action
class ProductionLot(models.Model): _inherit = 'stock.production.lot' purchase_order_ids = fields.Many2many( 'purchase.order', string="Purchase Orders", compute='_compute_purchase_order_ids', readonly=True, store=False) purchase_order_count = fields.Integer( 'Purchase order count', compute='_compute_purchase_order_ids') @api.depends('name') def _compute_purchase_order_ids(self): for lot in self: stock_moves = self.env['stock.move.line'].search([ ('lot_id', '=', lot.id), ('state', '=', 'done') ]).mapped('move_id') stock_moves = stock_moves.search([ ('id', 'in', stock_moves.ids) ]).filtered(lambda move: move.picking_id.location_id.usage == 'supplier' and move.state == 'done') lot.purchase_order_ids = stock_moves.mapped( 'purchase_line_id.order_id') lot.purchase_order_count = len(lot.purchase_order_ids) def action_view_po(self): self.ensure_one() action = self.env.ref('purchase.purchase_form_action').read()[0] action['domain'] = [('id', 'in', self.mapped('purchase_order_ids.id'))] return action
class ProductTemplate(models.Model): _inherit = "product.template" optional_product_ids = fields.Many2many( 'product.template', 'product_optional_rel', 'src_id', 'dest_id', string='Optional Products', help="Optional Products are suggested " "whenever the customer hits *Add to Cart* (cross-sell strategy, " "e.g. for computers: warranty, software, etc.).")
class ResCountryGroup(models.Model): _inherit = 'res.country.group' pricelist_ids = fields.Many2many('product.pricelist', 'res_country_group_pricelist_rel', 'res_country_group_id', 'pricelist_id', string='Pricelists')
class PosDetails(models.TransientModel): _name = 'pos.details.wizard' _description = 'Point of Sale Details Report' def _default_start_date(self): """ Find the earliest start_date of the latests sessions """ # restrict to configs available to the user config_ids = self.env['pos.config'].search([]).ids # exclude configs has not been opened for 2 days self.env.cr.execute( """ SELECT max(start_at) as start, config_id FROM pos_session WHERE config_id = ANY(%s) AND start_at > (NOW() - INTERVAL '2 DAYS') GROUP BY config_id """, (config_ids, )) latest_start_dates = [ res['start'] for res in self.env.cr.dictfetchall() ] # earliest of the latest sessions return latest_start_dates and min( latest_start_dates) or fields.Datetime.now() start_date = fields.Datetime(required=True, default=_default_start_date) end_date = fields.Datetime(required=True, default=fields.Datetime.now) pos_config_ids = fields.Many2many( 'pos.config', 'pos_detail_configs', default=lambda s: s.env['pos.config'].search([])) @api.onchange('start_date') def _onchange_start_date(self): if self.start_date and self.end_date and self.end_date < self.start_date: self.end_date = self.start_date @api.onchange('end_date') def _onchange_end_date(self): if self.end_date and self.end_date < self.start_date: self.start_date = self.end_date @api.multi def generate_report(self): if (not self.env.user.company_id.logo): raise UserError( _("You have to set a logo or a layout for your company.")) elif (not self.env.user.company_id.external_report_layout_id): raise UserError( _("You have to set your reports's header and footer layout.")) data = { 'date_start': self.start_date, 'date_stop': self.end_date, 'config_ids': self.pos_config_ids.ids } return self.env.ref('point_of_sale.sale_details_report').report_action( [], data=data)
class Partner(models.Model): _inherit = 'res.partner' website_tag_ids = fields.Many2many('res.partner.tag', 'res_partner_res_partner_tag_rel', 'partner_id', 'tag_id', string='Website tags')
class AccountAnalyticLine(models.Model): _name = 'account.analytic.line' _description = 'Analytic Line' _order = 'date desc, id desc' @api.model def _default_user(self): return self.env.context.get('user_id', self.env.user.id) name = fields.Char('Description', required=True) date = fields.Date('Date', required=True, index=True, default=fields.Date.context_today) amount = fields.Monetary('Amount', required=True, default=0.0) unit_amount = fields.Float('Quantity', default=0.0) product_uom_id = fields.Many2one('uom.uom', string='Unit of Measure') account_id = fields.Many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='restrict', index=True) partner_id = fields.Many2one('res.partner', string='Partner') user_id = fields.Many2one('res.users', string='User', default=_default_user) tag_ids = fields.Many2many('account.analytic.tag', 'account_analytic_line_tag_rel', 'line_id', 'tag_id', string='Tags', copy=True) company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True, default=lambda self: self.env.user.company_id) currency_id = fields.Many2one(related="company_id.currency_id", string="Currency", readonly=True, store=True, compute_sudo=True) group_id = fields.Many2one('account.analytic.group', related='account_id.group_id', store=True, readonly=True, compute_sudo=True) @api.multi @api.constrains('company_id', 'account_id') def _check_company_id(self): for line in self: if line.account_id.company_id and line.company_id.id != line.account_id.company_id.id: raise ValidationError( _('The selected account belongs to another company that the one you\'re trying to create an analytic item for' ))
class StockRulesReport(models.TransientModel): _inherit = 'stock.rules.report' so_route_ids = fields.Many2many('stock.location.route', string='Apply specific rotues', domain="[('sale_selectable', '=', True)]", help="Choose to apply SO lines specific routes.") def _prepare_report_data(self): data = super(StockRulesReport, self)._prepare_report_data() data['so_route_ids'] = self.so_route_ids.ids return data
class CountryGroup(models.Model): _description = "Country Group" _name = 'res.country.group' name = fields.Char(required=True, translate=True) country_ids = fields.Many2many('res.country', 'res_country_res_country_group_rel', 'res_country_group_id', 'res_country_id', string='Countries')
class AccountInvoiceLine(models.Model): _inherit = 'account.invoice.line' _order = 'invoice_id, sequence, id' sale_line_ids = fields.Many2many('sale.order.line', 'sale_order_line_invoice_rel', 'invoice_line_id', 'order_line_id', string='Sales Order Lines', readonly=True, copy=False)
class StockRulesReport(models.TransientModel): _name = 'stock.rules.report' _description = 'Stock Rules report' product_id = fields.Many2one('product.product', string='Product', required=True) product_tmpl_id = fields.Many2one('product.template', String='Product Template', required=True) warehouse_ids = fields.Many2many( 'stock.warehouse', string='Warehouses', required=True, help="Show the routes that apply on selected warehouses.") product_has_variants = fields.Boolean('Has variants', default=False, required=True) @api.model def default_get(self, fields): res = super(StockRulesReport, self).default_get(fields) product_tmpl_id = False if 'product_id' in fields: if self.env.context.get('default_product_id'): product_id = self.env['product.product'].browse( self.env.context['default_product_id']) product_tmpl_id = product_id.product_tmpl_id res['product_tmpl_id'] = product_id.product_tmpl_id.id res['product_id'] = product_id.id elif self.env.context.get('default_product_tmpl_id'): product_tmpl_id = self.env['product.template'].browse( self.env.context['default_product_tmpl_id']) res['product_tmpl_id'] = product_tmpl_id.id res['product_id'] = product_tmpl_id.product_variant_id.id if len(product_tmpl_id.product_variant_ids) > 1: res['product_has_variants'] = True if 'warehouse_ids' in fields: warehouse_id = self.env['stock.warehouse'].search([], limit=1).id res['warehouse_ids'] = [(6, 0, [warehouse_id])] return res def _prepare_report_data(self): data = { 'product_id': self.product_id.id, 'warehouse_ids': self.warehouse_ids.ids, } return data def print_report(self): self.ensure_one() data = self._prepare_report_data() return self.env.ref('stock.action_report_stock_rule').report_action( None, data=data)
class ImportInvoiceImportWizard(models.TransientModel): _name = 'account.invoice.import.wizard' _description = 'Import Your Vendor Bills from Files.' def _get_default_journal_id(self): return self.env['account.journal'].search([('type', '=', 'purchase')], limit=1) attachment_ids = fields.Many2many('ir.attachment', string='Files') journal_id = fields.Many2one(string="Journal", comodel_name="account.journal", required=True, domain="[('type', '=', 'purchase')]", default=_get_default_journal_id, help="Journal where to generate the bills") @api.multi def _create_invoice_from_file(self, attachment): self = self.with_context(default_journal_id=self.journal_id.id) invoice_form = Form(self.env['account.invoice'], view='account.invoice_supplier_form') invoice = invoice_form.save() attachment.write({ 'res_model': 'account.invoice', 'res_id': invoice.id }) invoice.message_post(attachment_ids=[attachment.id]) return invoice @api.multi def create_invoices(self): ''' Create the invoices from files. :return: A action redirecting to account.invoice tree/form view. ''' if not self.attachment_ids: return invoices = self.env['account.invoice'] for attachment in self.attachment_ids: invoices += self._create_invoice_from_file(attachment) action_vals = { 'name': _('Invoices'), 'domain': [('id', 'in', invoices.ids)], 'view_type': 'form', 'res_model': 'account.invoice', 'view_id': False, 'type': 'ir.actions.act_window', } if len(invoices) == 1: action_vals.update({'res_id': invoices[0].id, 'view_mode': 'form'}) else: action_vals['view_mode'] = 'tree,form' return action_vals
class ProjectTaskType(models.Model): _name = 'project.task.type' _description = 'Task Stage' _order = 'sequence, id' def _get_default_project_ids(self): default_project_id = self.env.context.get('default_project_id') return [default_project_id] if default_project_id else None name = fields.Char(string='Stage Name', required=True, translate=True) description = fields.Text(translate=True) sequence = fields.Integer(default=1) project_ids = fields.Many2many('project.project', 'project_task_type_rel', 'type_id', 'project_id', string='Projects', default=_get_default_project_ids) legend_priority = fields.Char( string='Starred Explanation', translate=True, help='Explanation text to help users using the star on tasks or issues in this stage.') legend_blocked = fields.Char( 'Red Kanban Label', default=lambda s: _('Blocked'), translate=True, required=True, help='Override the default value displayed for the blocked state for kanban selection, when the task or issue is in that stage.') legend_done = fields.Char( 'Green Kanban Label', default=lambda s: _('Ready for Next Stage'), translate=True, required=True, help='Override the default value displayed for the done state for kanban selection, when the task or issue is in that stage.') legend_normal = fields.Char( 'Grey Kanban Label', default=lambda s: _('In Progress'), translate=True, required=True, help='Override the default value displayed for the normal state for kanban selection, when the task or issue is in that stage.') mail_template_id = fields.Many2one( 'mail.template', string='Email Template', domain=[('model', '=', 'project.task')], help="If set an email will be sent to the customer when the task or issue reaches this step.") fold = fields.Boolean(string='Folded in Kanban', help='This stage is folded in the kanban view when there are no records in that stage to display.') rating_template_id = fields.Many2one( 'mail.template', string='Rating Email Template', domain=[('model', '=', 'project.task')], help="If set and if the project's rating configuration is 'Rating when changing stage', then an email will be sent to the customer when the task reaches this step.") auto_validation_kanban_state = fields.Boolean('Automatic kanban status', default=False, help="Automatically modify the kanban state when the customer replies to the feedback for this stage.\n" " * A good feedback from the customer will update the kanban state to 'ready for the new stage' (green bullet).\n" " * A medium or a bad feedback will set the kanban state to 'blocked' (red bullet).\n") @api.multi def unlink(self): stages = self default_project_id = self.env.context.get('default_project_id') if default_project_id: shared_stages = self.filtered(lambda x: len(x.project_ids) > 1 and default_project_id in x.project_ids.ids) tasks = self.env['project.task'].with_context(active_test=False).search([('project_id', '=', default_project_id), ('stage_id', 'in', self.ids)]) if shared_stages and not tasks: shared_stages.write({'project_ids': [(3, default_project_id)]}) stages = self.filtered(lambda x: x not in shared_stages) return super(ProjectTaskType, stages).unlink()
class PosConfig(models.Model): _inherit = 'pos.config' iface_splitbill = fields.Boolean( string='Bill Splitting', help='Enables Bill Splitting in the Point of Sale.') iface_printbill = fields.Boolean( string='Bill Printing', help='Allows to print the Bill before payment.') iface_orderline_notes = fields.Boolean( string='Orderline Notes', help='Allow custom notes on Orderlines.') floor_ids = fields.One2many( 'restaurant.floor', 'pos_config_id', string='Restaurant Floors', help='The restaurant floors served by this point of sale.') printer_ids = fields.Many2many('restaurant.printer', 'pos_config_printer_rel', 'config_id', 'printer_id', string='Order Printers') is_table_management = fields.Boolean('Table Management') is_order_printer = fields.Boolean('Order Printer') module_pos_restaurant = fields.Boolean(default=True) @api.onchange('iface_tipproduct') def _onchange_tipproduct(self): if self.iface_tipproduct: self.tip_product_id = self.env.ref( 'point_of_sale.product_product_tip', False) else: self.tip_product_id = False @api.onchange('module_pos_restaurant') def _onchange_module_pos_restaurant(self): if not self.module_pos_restaurant: self.update({ 'iface_printbill': False, 'iface_splitbill': False, 'iface_tipproduct': False, 'is_order_printer': False, 'is_table_management': False, 'iface_orderline_notes': False }) @api.onchange('is_table_management') def _onchange_is_table_management(self): if not self.is_table_management: self.floor_ids = [(5, 0, 0)] @api.onchange('is_order_printer') def _onchange_is_order_printer(self): if not self.is_order_printer: self.printer_ids = [(5, 0, 0)]
class AccountPrintJournal(models.TransientModel): _inherit = "account.common.journal.report" _name = "account.print.journal" _description = "Account Print Journal" sort_selection = fields.Selection([('date', 'Date'), ('move_name', 'Journal Entry Number'),], 'Entries Sorted by', required=True, default='move_name') journal_ids = fields.Many2many('account.journal', string='Journals', required=True, default=lambda self: self.env['account.journal'].search([('type', 'in', ['sale', 'purchase'])])) def _print_report(self, data): data = self.pre_print_report(data) data['form'].update({'sort_selection': self.sort_selection}) return self.env.ref('account.action_report_journal').with_context(landscape=True).report_action(self, data=data)
class TrackTag(models.Model): _name = "event.track.tag" _description = 'Event Track Tag' _order = 'name' name = fields.Char('Tag') track_ids = fields.Many2many('event.track', string='Tracks') color = fields.Integer(string='Color Index') _sql_constraints = [ ('name_uniq', 'unique (name)', "Tag name already exists !"), ]