def name_get(self): res = [] for payment in self: if payment.name: res.append((payment.id, '%s %s' % (payment.name, formatLang(self.env, payment.amount, currency_obj=payment.currency_id)))) else: res.append((payment.id, formatLang(self.env, payment.amount, currency_obj=payment.currency_id))) return res
def get_valid_values(self): if self.question_type == 'qualitative': self.valid_values = ", ".join( [x.name for x in self.possible_ql_values if x.ok]) else: self.valid_values = "%s ~ %s" % (formatLang( self.env, self.min_value), formatLang(self.env, self.max_value)) if self.env.ref("product.group_uom") in self.env.user.groups_id: self.valid_values += " %s" % self.test_uom_id.name
def _compute_valid_values(self): for l in self: if l.question_type == 'qualitative': l.valid_values = \ ", ".join([x.name for x in l.possible_ql_values if x.ok]) else: l.valid_values = "%s ~ %s" % (formatLang( self.env, l.min_value), formatLang(self.env, l.max_value)) if self.env.ref("uom.group_uom") \ in self.env.user.groups_id: l.valid_values += " %s" % l.test_uom_id.name
def _get_sold_items(self): sols = self._get_sale_order_lines() number_sale_orders = len(sols.order_id) sold_items = { 'allow_billable': self.allow_billable, 'data': [], 'number_sols': len(sols), 'total_sold': 0, 'effective_sold': 0, 'company_unit_name': self.env.company.timesheet_encode_uom_id.name } product_uom_unit = self.env.ref('uom.product_uom_unit') for sol in sols: name = [x[1] for x in sol.name_get() ] if number_sale_orders > 1 else sol.name qty_delivered = sol.product_uom._compute_quantity( sol.qty_delivered, self.env.company.timesheet_encode_uom_id, raise_if_failure=False) product_uom_qty = sol.product_uom._compute_quantity( sol.product_uom_qty, self.env.company.timesheet_encode_uom_id, raise_if_failure=False) if qty_delivered > 0 or product_uom_qty > 0: sold_items['data'].append({ 'name': name, 'value': '%s / %s %s' % (formatLang(self.env, qty_delivered, 1), formatLang(self.env, product_uom_qty, 1), sol.product_uom.name if sol.product_uom == product_uom_unit else self.env.company.timesheet_encode_uom_id.name), 'color': 'red' if qty_delivered > product_uom_qty else 'black' }) #We only want to consider hours and days for this calculation, and eventually units if the service policy is not based on milestones if sol.product_uom.category_id == self.env.company.timesheet_encode_uom_id.category_id or ( sol.product_uom == product_uom_unit and sol.product_id.service_policy != 'delivered_manual'): sold_items['total_sold'] += product_uom_qty sold_items[ 'effective_sold'] += sol.product_uom._compute_quantity( qty_delivered, self.env.company.timesheet_encode_uom_id, raise_if_failure=False) remaining = sold_items['total_sold'] - sold_items['effective_sold'] sold_items['remaining'] = { 'value': remaining, 'color': 'red' if remaining < 0 else 'black', } return sold_items
def _compute_valid_values(self): for insp_line in self: if insp_line.question_type == "qualitative": insp_line.valid_values = ", ".join( [x.name for x in insp_line.possible_ql_values if x.ok]) else: insp_line.valid_values = "{} ~ {}".format( formatLang(self.env, insp_line.min_value), formatLang(self.env, insp_line.max_value), ) if self.env.ref("uom.group_uom") in self.env.user.groups_id: insp_line.valid_values += " %s" % insp_line.test_uom_id.name
def name_get(self): currency_id = self.env.user.company_id.currency_id res = dict(super(LunchTopping, self).name_get()) for topping in self: price = formatLang(self.env, topping.price, currency_obj=currency_id) res[topping.id] = '%s %s' % (topping.name, price) return list(res.items())
def _get_profitability_values(self, project): costs_revenues = project.analytic_account_id and project.allow_billable if not (self.user_has_groups('project.group_project_manager') and costs_revenues): return {} profitability_items = project._get_profitability_items(False) costs = sum(profitability_items['costs']['total'].values()) revenues = sum(profitability_items['revenues']['total'].values()) margin = revenues + costs return { 'analytic_account_id': project.analytic_account_id, 'costs': costs, 'costs_formatted': format_amount(self.env, -costs, project.currency_id), 'revenues': revenues, 'revenues_formatted': format_amount(self.env, revenues, project.currency_id), 'margin': margin, 'margin_formatted': format_amount(self.env, margin, project.currency_id), 'margin_percentage': formatLang( self.env, not float_utils.float_is_zero(costs, precision_digits=2) and (margin / -costs) * 100 or 0.0, digits=0), }
def _get_profitability_values(self, project): costs_revenues = project.analytic_account_id and project.allow_billable timesheets = project.allow_timesheets and self.user_has_groups( 'hr_timesheet.group_hr_timesheet_user') if not (self.user_has_groups('project.group_project_manager') and (costs_revenues or timesheets)): return {} profitability = project._get_profitability_common() return { 'analytic_account_id': project.analytic_account_id, 'costs': format_amount(self.env, -profitability['costs'], self.env.company.currency_id), 'revenues': format_amount(self.env, profitability['revenues'], self.env.company.currency_id), 'margin': profitability['margin'], 'margin_formatted': format_amount(self.env, profitability['margin'], self.env.company.currency_id), 'margin_percentage': formatLang( self.env, not float_utils.float_is_zero(profitability['costs'], precision_digits=2) and -(profitability['margin'] / profitability['costs']) * 100 or 0.0, digits=0), }
def name_get(self): currency_id = self.env.company.currency_id res = dict(super(LunchTopping, self).name_get()) for topping in self: price = formatLang(self.env, topping.price, currency_obj=currency_id) res[topping.id] = '%s %s' % (topping.name, price) return list(res.items())
def _get_pricelist_item_name_price(self): for item in self: if item.categ_id and item.applied_on == '2_product_category': item.name = _("Category: %s") % (item.categ_id.display_name) elif item.product_tmpl_id and item.applied_on == '1_product': item.name = _("Product: %s") % ( item.product_tmpl_id.display_name) elif item.product_id and item.applied_on == '0_product_variant': item.name = _("Variant: %s") % (item.product_id.with_context( display_default_code=False).display_name) else: item.name = _("All Products") if item.compute_price == 'fixed': item.price = formatLang(item.env, item.fixed_price, monetary=True, dp="Product Price", currency_obj=item.currency_id) elif item.compute_price == 'percentage': item.price = _("%s %% discount", item.percent_price) else: item.price = _( "%(percentage)s %% discount and %(price)s surcharge", percentage=item.price_discount, price=item.price_surcharge)
def name_get(self): result = [] for inv in self: number = inv.number if inv.number else '' if self.env.context.get('show_date_invoice'): #and inv.date_invoice: number += ': ' + formatLang(self.env, inv.amount_total, currency_obj=inv.currency_id) result.append((inv.id, number)) return result
def _get_template_values(self, project): milestones = self._get_milestone_values(project) return { 'user': self.env.user, 'project': project, 'show_activities': milestones['show_section'], 'milestones': milestones, 'format_lang': lambda value, digits: formatLang(self.env, value, digits=digits), }
def format_value(self, value, currency=False): if self.env.context.get('no_format'): return value currency_id = currency or self.env.user.company_id.currency_id if currency_id.is_zero(value): # don't print -0.0 in reports value = abs(value) res = formatLang(self.env, value, currency_obj=currency_id) return res
def convert_2float(self, value, precision=2, currency_obj=None, context=None): fmt = '%f' if precision is None else '%.{precision}f' lang_code = self.env.context.get('lang') or 'en_US' lang = self.env['res.lang'] formatted = formatLang(self.env, value, currency_obj=currency_obj) return formatted
def convert_2float(self, value, precision=2, currency_obj=None, context=None): fmt = '%f' if precision is None else '%.{precision}f' lang_code = self.env.context.get('lang') or 'en_US' lang = self.env['res.lang'] formatted = formatLang(self.env, value, currency_obj=currency_obj) #if currency_obj: # if currency_obj.position == 'before': # formatted = currency_obj.symbol + ' ' + formatted #else: # formatted = formatted + ' ' + currency_obj.symbol return formatted
def name_get(self): res = [] if self.env.context.get('name_pos', False): for element in self: name = "%s(Monto: %s)" % ( element.journal_id.display_name, formatLang(self.env, element.amount, monetary=True)) res.append((element.id, name)) else: res = super(AccountBankStatementLine, self).name_get() return res
def name_get(self): result = [] for doc in self: name = doc.name or '' if doc.reference: name += ' - ' + doc.reference amount = doc.amount if doc.purchase_order_id and doc.purchase_order_id.invoice_status == 'no': amount = 0.0 name += ': ' + formatLang(self.env, amount, monetary=True, currency_obj=doc.currency_id) result.append((doc.id, name)) return result
def name_get(self): result = [] for doc in self: name = doc.name or '' if doc.reference: name += ' - ' + doc.reference amount = doc.amount if doc.purchase_order_id and doc.purchase_order_id.invoice_status == 'no': amount = 0.0 name += ': ' + formatLang(self.env, amount, monetary=True, currency_obj=doc.currency_id) result.append((doc.id, name)) return result
def _batch_report(self, workbook, ws, ws_params, data, batch): ws.set_portrait() ws.fit_to_pages(1, 0) ws.set_header(self.xls_headers["standard"]) ws.set_footer(self.xls_footers["standard"]) self._set_column_width(ws, ws_params) row_pos = 0 if len(batch) == 1: ws_params["title"] = ( batch.name + " - Draft Report" if batch.state_approved else "Report" ) row_pos = self._write_ws_title(ws, row_pos, ws_params) row_pos = self._write_line( ws, row_pos, ws_params, col_specs_section="header", default_format=self.format_theader_blue_center, ) ws.freeze_panes(row_pos, 0) wl = ws_params["wanted_list"] batch_totals = {} batch_lines = {} for slip in batch.slip_ids: slip_data = {} for line in slip.details_by_disbursement_rule_category: slip_data[line.disbursement_rule_id.code] = formatLang( self.env, line.total, currency_obj=slip.currency_id ) if line.disbursement_rule_id.code not in batch_totals: batch_totals[line.disbursement_rule_id.code] = line.total else: batch_totals[line.disbursement_rule_id.code] += line.total batch_lines[slip.id] = slip_data row_pos = self._write_line( ws, row_pos, ws_params, col_specs_section="data", render_space={ "beneficiary": slip.beneficiary_id, "slip": slip, "slip_lines": slip_data, }, default_format=self.format_tcell_left, )
def _get_move_lines_str(self): """returns all move lines related to invoice in string""" expiration_dates_str = "" move_line_obj = self.env["account.move.line"] if self.move_id: move_lines = move_line_obj.\ search([('move_id', '=', self.move_id.id), ('account_id.internal_type', 'in', ['payable', 'receivable']), ('date_maturity', "!=", False)], order="date_maturity asc") for line in move_lines: date = time.strptime(line.date_maturity, "%Y-%m-%d") date = datetime.fromtimestamp(mktime(date)) date = date.strftime("%d/%m/%Y") expiration_dates_str += date + \ " -------------> " + \ (self.type in ('out_invoice', 'in_refund') and tools.formatLang(self.env, line.debit) or (self.type in ('in_invoice', 'out_refund') and tools.formatLang(self.env, line.credit) or "0")) + "\n" self.expiration_dates_str = expiration_dates_str
def ca_ttype_product(self): url = False filename = '' image_field = 'image_chat' # to set dynamic: self.res_filed if not self.res_id or self.res_model != 'product.product': raise ValidationError('Product type is required.') prod_id = self.env[self.res_model].browse(self.res_id) if not prod_id: raise ValidationError('Product is required.') # caption ---------- # or prod_id.name_get()[0][1] list_price = formatLang(self.env, prod_id.list_price, currency_obj=self.env.user.company_id.currency_id) caption = '%s\n%s / %s' % (self.text or prod_id.name.strip(), list_price, prod_id.uom_id.name) # image ---------- field_image = getattr(prod_id, image_field) if field_image: filename = secure_filename(prod_id.name) attach = get_binary_attach(self.env, self.res_model, self.res_id, image_field, fields_ret=['mimetype']) mimetype = attach and attach['mimetype'] if mimetype: ext = mimetype.split('/') if len(ext) == 2: filename = secure_filename('%s.%s' % (prod_id.name, ext[1])) prod_id, url = self.get_url_image(res_model=self.res_model, res_id=self.res_id, field=image_field, prod_id=prod_id) # send ---------- if not url: # Simple text message ret = { 'type': 'text', 'text': caption } return ret else: ret = { 'type': 'file', 'text': caption, 'filename': filename, 'url': url } return ret
def onchange_rea_data(self): self.company_registry = '' rea_member_type = '' if (self.rea_office or self.rea_code or self.rea_capital or self.rea_member_type or self.rea_liquidation_state): if self.rea_member_type: rea_member_type = dict( self.env['res.partner']._fields['rea_member_type']. _description_selection(self.env))[self.rea_member_type] rea_liquidation_state = '' if self.rea_liquidation_state: rea_liquidation_state = dict( self.env['res.partner']._fields['rea_liquidation_state']. _description_selection( self.env))[self.rea_liquidation_state] # using always €, as this is a registry of Italian companies company_registry = _("%s - %s / Share Cap. %s € / %s / %s") % ( self.rea_office.code or '', self.rea_code or '', formatLang(self.env, self.rea_capital), rea_member_type, rea_liquidation_state) self.company_registry = company_registry
def name_get(self): """ Override name get to show PO line order, name, qty, uom and price """ result = [] for doc in self: price = formatLang(self.env, doc.price_unit, monetary=True, currency_obj=doc.currency_id) name = "[{}] {}: {} {}, {}".format( doc.order_id.name, doc.name, doc.product_qty, doc.product_uom.name, price, ) result.append((doc.id, name)) return result
def generate_xlsx_report(self, workbook, data, partners): date_from = data.get('date_from') date_to = data.get('date_to') product_ids = data.get('product_ids') and data.get( 'product_ids').split(',') lot_ids = data.get('lot_ids') and data.get('lot_ids').split(',') if product_ids: product_ids = [int(p) for p in product_ids if p != '0'] res = self.env[ 'report.mrp_mo_cost_report_ae.report_mo_structure']._get_report_data( bom_id=False, searchQty=False, searchVariant=False, lot_id=lot_ids, product_id=product_ids, product_name=False, date_from=date_from, date_to=date_to) report_name = 'MO Structure & Cost Report' sheet = workbook.add_worksheet(report_name[:31]) bold = workbook.add_format({'bold': True}) merge_format = workbook.add_format({ 'bold': 2, 'border': 1, 'align': 'center', 'valign': 'vcenter', 'font_size': 26, }) right_format = workbook.add_format({'align': 'right'}) sheet.set_column('A:H', 17) sheet.set_row(0, 30) sheet.merge_range('C1:G1', report_name, merge_format) sheet.write(1, 0, 'Product', bold) sheet.write(1, 1, 'MO', bold) sheet.write(1, 2, 'Production Qty', bold) sheet.write(1, 3, 'Production Unit Cost', bold) sheet.write(1, 4, 'Production Cost', bold) sheet.write(1, 5, 'Component Name', bold) sheet.write(1, 6, 'Consumption Qty', bold) col = 6 if self.env.user.user_has_groups('uom.group_uom'): sheet.write(1, col, 'Component UoM', bold) col += 1 sheet.write(1, col, 'Unit Cost', bold) col += 1 sheet.write(1, col, 'Component Cost', bold) row = 2 for obj in res.get('lines'): sheet.write(row, 0, obj.get('mo').product_id.display_name) sheet.write(row, 1, obj.get('mo').name) sheet.write(row, 2, obj.get('qty')) currency = obj.get('currency') mo_cost = formatLang(self.env, obj.get('mo_cost'), currency_obj=currency) unit_cost = obj.get('mo_cost') / obj.get('qty') mo_unit_cost = formatLang(self.env, unit_cost, currency_obj=currency) sheet.write(row, 3, mo_unit_cost, right_format) sheet.write(row, 4, mo_cost, right_format) row += 1 for component in obj.get('components'): sheet.write(row, 5, component.product_id.display_name) sheet.write(row, 6, component.quantity_done) col = 7 if self.env.user.user_has_groups('uom.group_uom'): sheet.write(row, col, component.product_uom.name) col += 1 price_unit = formatLang(self.env, component.price_unit, currency_obj=currency) sheet.write(row, col, price_unit, right_format) col += 1 component_cost = formatLang(self.env, abs(component.price_unit * component.quantity_done), currency_obj=currency) sheet.write(row, col, component_cost, right_format) row += 1 row += 1
def _get_profitability_values(self, project): costs_revenues = project.analytic_account_id and project.allow_billable timesheets = project.allow_timesheets and self.user_has_groups( 'hr_timesheet.group_hr_timesheet_user') if not (self.user_has_groups('project.group_project_manager') and (costs_revenues or timesheets)): return {} this_month = fields.Date.context_today(self) + relativedelta(day=1) previous_month = this_month + relativedelta(months=-1, day=1) result = { 'allow_timesheets': timesheets, 'allow_costs_and_revenues': costs_revenues, 'analytic_account_id': project.analytic_account_id, 'month': format_date(self.env, this_month, date_format='LLLL y'), 'previous_month': format_date(self.env, previous_month, date_format='LLLL'), 'is_timesheet_uom_hour': self.env.company._is_timesheet_hour_uom(), 'timesheet_uom': self.env.company._timesheet_uom_text(), 'timesheet_unit_amount': '', 'previous_timesheet_unit_amount': '', 'timesheet_trend': '', 'costs': '', 'revenues': '', 'margin': '', 'margin_formatted': '', 'margin_percentage': '', 'billing_rate': '', } if timesheets: timesheets_per_month = self.env[ 'account.analytic.line'].read_group( [('project_id', '=', project.id), ('date', '>=', previous_month)], ['date', 'unit_amount'], ['date:month']) timesheet_unit_amount = { ts['__range']['date']['from']: ts['unit_amount'] for ts in timesheets_per_month } this_amount = timesheet_unit_amount.get( this_month.replace(day=1).strftime(DEFAULT_SERVER_DATE_FORMAT), 0.0) previous_amount = timesheet_unit_amount.get( previous_month.replace( day=1).strftime(DEFAULT_SERVER_DATE_FORMAT), 0.0) result.update({ 'timesheet_unit_amount': formatLang( self.env, project._convert_project_uom_to_timesheet_encode_uom( this_amount), digits=0), 'previous_timesheet_unit_amount': formatLang( self.env, project._convert_project_uom_to_timesheet_encode_uom( previous_amount), digits=0), 'timesheet_trend': formatLang(self.env, previous_amount > 0 and ((this_amount / previous_amount) - 1) * 100 or 0.0, digits=0), }) if costs_revenues: profitability = project._get_profitability_common( costs_revenues=True, timesheets=False) result.update({ 'costs': format_amount(self.env, -profitability['costs'], self.env.company.currency_id), 'revenues': format_amount(self.env, profitability['revenues'], self.env.company.currency_id), 'margin': profitability['margin'], 'margin_formatted': format_amount(self.env, profitability['margin'], self.env.company.currency_id), 'margin_percentage': formatLang( self.env, not float_utils.float_is_zero(profitability['costs'], precision_digits=2) and -(profitability['margin'] / profitability['costs']) * 100 or 0.0, digits=0), 'billing_rate': formatLang( self.env, not float_utils.float_is_zero(profitability['costs'], precision_digits=2) and -(profitability['revenues'] / profitability['costs']) * 100 or 0.0, digits=0), }) return result
def formatLang(self, value, *args): return formatLang(self.env, value, *args)
def get_journal_dashboard_datas(self): currency = self.currency_id or self.company_id.currency_id number_to_reconcile = last_balance = account_sum = 0 title = '' number_draft = number_waiting = number_late = 0 sum_draft = sum_waiting = sum_late = 0.0 if self.type in ['bank', 'cash']: last_bank_stmt = self.env['account.bank.statement'].search( [('journal_id', 'in', self.ids)], order="date desc, id desc", limit=1) last_balance = last_bank_stmt and last_bank_stmt[0].balance_end or 0 #Get the number of items to reconcile for that bank journal self.env.cr.execute( """SELECT COUNT(DISTINCT(line.id)) FROM account_bank_statement_line AS line LEFT JOIN account_bank_statement AS st ON line.statement_id = st.id WHERE st.journal_id IN %s AND st.state = 'open' AND line.amount != 0.0 AND not exists (select 1 from account_move_line aml where aml.statement_line_id = line.id) """, (tuple(self.ids), )) number_to_reconcile = self.env.cr.fetchone()[0] # optimization to read sum of balance from account_move_line account_ids = tuple(ac for ac in [ self.default_debit_account_id.id, self.default_credit_account_id.id ] if ac) if account_ids: amount_field = 'balance' if ( not self.currency_id or self.currency_id == self.company_id.currency_id) else 'amount_currency' query = """SELECT sum(%s) FROM account_move_line WHERE account_id in %%s AND date <= %%s;""" % ( amount_field, ) self.env.cr.execute(query, ( account_ids, fields.Date.today(), )) query_results = self.env.cr.dictfetchall() if query_results and query_results[0].get('sum') != None: account_sum = query_results[0].get('sum') #TODO need to check if all invoices are in the same currency than the journal!!!! elif self.type in ['sale', 'purchase']: title = _('Bills to pay') if self.type == 'purchase' else _( 'Invoices owed to you') (query, query_args) = self._get_open_bills_to_pay_query() self.env.cr.execute(query, query_args) query_results_to_pay = self.env.cr.dictfetchall() (query, query_args) = self._get_draft_bills_query() self.env.cr.execute(query, query_args) query_results_drafts = self.env.cr.dictfetchall() today = datetime.today().strftime('%Y-%m-%d %H:%M:%S') query = """SELECT amount_total, currency_id AS currency, type FROM account_invoice WHERE journal_id = %s AND date < %s AND state = 'open';""" self.env.cr.execute(query, (self.id, today)) late_query_results = self.env.cr.dictfetchall() (number_waiting, sum_waiting) = self._count_results_and_sum_amounts( query_results_to_pay, currency) (number_draft, sum_draft) = self._count_results_and_sum_amounts( query_results_drafts, currency) (number_late, sum_late) = self._count_results_and_sum_amounts( late_query_results, currency) return { 'number_to_reconcile': number_to_reconcile, 'account_balance': formatLang(self.env, account_sum, currency_obj=self.currency_id or self.company_id.currency_id), 'last_balance': formatLang(self.env, last_balance, currency_obj=self.currency_id or self.company_id.currency_id), 'difference': (last_balance - account_sum) and formatLang( self.env, last_balance - account_sum, currency_obj=self.currency_id or self.company_id.currency_id) or False, 'number_draft': number_draft, 'number_waiting': number_waiting, 'number_late': number_late, 'sum_draft': formatLang(self.env, sum_draft or 0.0, currency_obj=self.currency_id or self.company_id.currency_id), 'sum_waiting': formatLang(self.env, sum_waiting or 0.0, currency_obj=self.currency_id or self.company_id.currency_id), 'sum_late': formatLang(self.env, sum_late or 0.0, currency_obj=self.currency_id or self.company_id.currency_id), 'currency_id': self.currency_id and self.currency_id.id or self.company_id.currency_id.id, 'bank_statements_source': self.bank_statements_source, 'title': title, }
def _make_commission(self): for move in self.filtered(lambda m: m.move_type in ['out_invoice', 'in_invoice', 'out_refund']): if move.move_type in ['out_invoice', 'in_invoice']: sign = 1 if move.commission_po_line_id or not move.referrer_id: continue else: sign = -1 if not move.commission_po_line_id: continue comm_by_rule = defaultdict(float) product = None subscription = None for line in move.invoice_line_ids: rule = line._get_commission_rule() if rule: if not product: product = rule.plan_id.product_id if not subscription: subscription = line.subscription_id commission = move.currency_id.round(line.price_subtotal * rule.rate / 100.0) comm_by_rule[rule] += commission # regulate commissions for r, amount in comm_by_rule.items(): if r.is_capped: amount = min(amount, r.max_commission) comm_by_rule[r] = amount total = sum(comm_by_rule.values()) if not total: continue # build description lines desc = f"{_('Commission on %s') % (move.name)}, {move.partner_id.name}, {formatLang(self.env, move.amount_untaxed, currency_obj=move.currency_id)}" if subscription: periods = { 'daily': 'days', 'weekly': 'weeks', 'monthly': 'months', 'yearly': 'years' } date_to = subscription.recurring_next_date date_from = fields.Date.subtract( date_to, **{ periods[subscription.recurring_rule_type]: subscription.recurring_interval }) desc += f"\n{subscription.code}, {_('from %s to %s') % (format_date(self.env, date_from), format_date(self.env, date_to))}" # extend the description to show the number of months to defer the expense over delta = relativedelta(date_to, date_from) n_months = delta.years * 12 + delta.months + delta.days // 30 if n_months: desc += f" ({_('%d month(s)') % (n_months)})" purchase = move._get_commission_purchase_order() line = self.env['purchase.order.line'].sudo().create({ 'name': desc, 'product_id': product.id, 'product_qty': 1, 'price_unit': total * sign, 'product_uom': product.uom_id.id, 'date_planned': fields.Datetime.now(), 'order_id': purchase.id, 'qty_received': 1, }) if move.move_type in ['out_invoice', 'in_invoice']: # link the purchase order line to the invoice move.commission_po_line_id = line msg_body = 'New commission. Invoice: <a href=# data-oe-model=account.move data-oe-id=%d>%s</a>. Amount: %s.' % ( move.id, move.name, formatLang(self.env, total, currency_obj=move.currency_id)) else: msg_body = 'Commission refunded. Invoice: <a href=# data-oe-model=account.move data-oe-id=%d>%s</a>. Amount: %s.' % ( move.id, move.name, formatLang(self.env, total, currency_obj=move.currency_id)) purchase.message_post(body=msg_body)
def get_proper_format(self, amount): number = formatLang(self.env, amount, monetary=True, currency_obj=self.currency_id) return number.rstrip('0').rstrip('.')