def get_line(self, values): 'Return the tax line for the keyword values' pool = Pool() TaxLine = pool.get('account.tax.line') line = TaxLine() try: amount = simple_eval(decistmt(self.amount), functions={'Decimal': Decimal}, names=values) except InvalidExpression as e: raise MoveTemplateExpressionError( gettext('account.msg_template_invalid_expression', expression=values, template=self.line.rec_name, error=e)) from e if not isinstance(amount, Decimal): raise MoveTemplateExpressionError( gettext('account.msg_not_number', result=amount, expression=self.move.rec_name)) amount = self.line.move.company.currency.round(amount) line.amount = amount line.type = self.type line.tax = self.tax return line
def get_line(self, values): 'Return the tax line for the keyword values' pool = Pool() TaxLine = pool.get('account.tax.line') line = TaxLine() amount = simple_eval(decistmt(self.amount), functions={'Decimal': Decimal}, names=values) amount = self.line.move.company.currency.round(amount) line.amount = amount line.code = self.code line.tax = self.tax return line
def get_line(self, values): 'Return the tax line for the keyword values' pool = Pool() TaxLine = pool.get('account.tax.line') line = TaxLine() amount = simple_eval(decistmt(self.amount), functions={'Decimal': Decimal}, names=values) amount = self.line.move.company.currency.round(amount) line.amount = amount line.type = self.type line.tax = self.tax return line
def get_line(self, origin, keywords, **context): pool = Pool() Line = pool.get('account.statement.line') context.setdefault('functions', {})['Decimal'] = Decimal context.setdefault('names', {}).update(keywords) currency = origin.statement.journal.currency amount = currency.round(simple_eval(decistmt(self.amount), **context)) party = self._get_party(origin, keywords) invoice = self._get_invoice(origin, keywords) if invoice and party and invoice.party != party: return if invoice and not party: party = invoice.party account = self.account if not account: if invoice: account = invoice.account elif party: with Transaction().set_context(date=origin.date): if amount > Decimal('0.0'): account = party.account_receivable_used else: account = party.account_payable_used if not account: return if not party: party = origin.party if account.party_required and not party: return if not account.party_required: party = None line = Line() line.statement = origin.statement line.number = origin.number line.description = origin.description line.origin = origin line.amount = amount line.date = origin.date line.party = party line.account = account line.invoice = invoice return line
def get_line(self, values): 'Return the move line for the keyword values' pool = Pool() Line = pool.get('account.move.line') Keyword = pool.get('account.move.template.keyword') line = Line() try: amount = simple_eval(decistmt(self.amount), functions={'Decimal': Decimal}, names=values) except InvalidExpression as e: raise MoveTemplateExpressionError( gettext('account.msg_move_template_invalid_expression', expression=values, template=self.move.rec_name, error=e)) from e if not isinstance(amount, Decimal): raise MoveTemplateExpressionError( gettext('account.msg_move_template_expession_not_number', value=amount, expression=self.move.name, template=self.move.rec_name)) amount = self.move.company.currency.round(amount) if self.operation == 'debit': line.debit = amount else: line.credit = amount line.account = self.account if self.party: line.party = values.get(self.party) if self.description: try: line.description = self.description.format( **dict(Keyword.format_values(self.move, values))) except KeyError as e: raise MoveTemplateExpressionError( gettext('account.msg_move_template_invalid_expression', expression=values, template=self.move.name, error=e)) from e line.tax_lines = [t.get_line(values) for t in self.taxes] return line
def get_line(self, values): 'Return the move line for the keyword values' pool = Pool() Line = pool.get('account.move.line') Keyword = pool.get('account.move.template.keyword') line = Line() amount = simple_eval(decistmt(self.amount), functions={'Decimal': Decimal}, names=values) amount = self.move.company.currency.round(amount) if self.operation == 'debit': line.debit = amount else: line.credit = amount line.account = self.account if self.party: line.party = values.get(self.party) if self.description: line.description = self.description.format( **dict(Keyword.format_values(self.move, values))) line.tax_lines = [t.get_line(values) for t in self.taxes] return line
def get_unit_price(self, **context): 'Return unit price (as Decimal)' context.setdefault('functions', {})['Decimal'] = Decimal return simple_eval(decistmt(self.formula), **context)
def get_amount(self, **context): 'Return amount (as Decimal)' context.setdefault('functions', {})['Decimal'] = Decimal return simple_eval(decistmt(self.formula), **context)
def get_cost_price(self, cost_price, **context): context.setdefault('names', {})['cost_price'] = cost_price context.setdefault('functions', {})['Decimal'] = Decimal return simple_eval(decistmt(self.cost_price), **context)
def compute_amount(self, **names): context = self.get_compute_amount_context(**names) return simple_eval(decistmt(self.formula), **context)