|
@@ -43,7 +43,8 @@ class PaymentsSales(http.Controller):
|
|
|
'rateSilent': user.company_id.currency_id.rate_silent,
|
|
|
'thousandsSeparator': user.company_id.currency_id.thousands_separator,
|
|
|
'decimalSeparator': user.company_id.currency_id.decimal_separator,
|
|
|
- 'decimalPlaces': user.company_id.currency_id.decimal_places
|
|
|
+ 'decimalPlaces': user.company_id.currency_id.decimal_places,
|
|
|
+ 'position': user.company_id.currency_id.position
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -72,18 +73,57 @@ class PaymentsSales(http.Controller):
|
|
|
for invoice in request.env['account.invoice'].search([('id', 'in', partner_invoice),('state', '=', 'open')]):
|
|
|
movelines = []
|
|
|
moves = []
|
|
|
- currency_symbol = ""
|
|
|
|
|
|
for move in invoice.move_id:
|
|
|
for moveline in move.line_id:
|
|
|
if moveline.amount_residual > 0 and moveline.state != "draft" and moveline.credit <= 0:
|
|
|
+ currencyAmount = []
|
|
|
+ decimal_precision = request.env['decimal.precision'].precision_get('Account')
|
|
|
+ # print("\n\n")
|
|
|
+ # # accountConfig = request.env['account.config.settings']
|
|
|
+ # import web_pdb; web_pdb.set_trace()
|
|
|
+ # print(request.env.user)
|
|
|
+ # print("\n")
|
|
|
+
|
|
|
+ # if (request.env.user.in_group_7):
|
|
|
+ # domain = [[('active', '=', True)], ['id', '=', user.company_id.currency_id.id]]
|
|
|
+ # else:
|
|
|
+ domain = [('active', '=', True)]
|
|
|
+
|
|
|
+
|
|
|
+ for currency in request.env['res.currency'].search(domain):
|
|
|
+ amount_currency = moveline.amount_currency
|
|
|
+
|
|
|
+ if moveline.amount_currency <= 0:
|
|
|
+ amount_currency = moveline.debit
|
|
|
+
|
|
|
+ currencyAmount.append({
|
|
|
+ 'id': currency.id,
|
|
|
+ 'name': currency.name,
|
|
|
+ 'displayName': currency.display_name,
|
|
|
+ 'base': currency.base,
|
|
|
+ 'accuracy': currency.accuracy,
|
|
|
+ 'rateSilent': currency.rate_silent,
|
|
|
+ 'rounding': currency.rounding,
|
|
|
+ 'symbol': currency.symbol,
|
|
|
+ 'position': currency.position,
|
|
|
+ 'thousandsSeparator': currency.thousands_separator,
|
|
|
+ 'decimalSeparator': currency.decimal_separator,
|
|
|
+ 'decimalPlaces': currency.decimal_places,
|
|
|
+ 'amountCurency': round(amount_currency * (currency.rate_silent/ invoice.currency_id.rate_silent), decimal_precision),
|
|
|
+ 'amountCurencyResidual': round((moveline.amount_residual_currency * (currency.rate_silent / invoice.currency_id.rate_silent)), decimal_precision)
|
|
|
+ })
|
|
|
+
|
|
|
movelines.append({
|
|
|
'id': moveline.id,
|
|
|
'amountResidual': moveline.amount_residual,
|
|
|
'credit': moveline.credit,
|
|
|
'debit': moveline.debit,
|
|
|
'dateMaturity': moveline.date_maturity,
|
|
|
- 'invoice': invoice.id
|
|
|
+ 'invoice': invoice.id,
|
|
|
+ 'amountCurrency': moveline.amount_currency if moveline.amount_currency > 0 else moveline.debit,
|
|
|
+ 'amountResidualCurrency': moveline.amount_residual_currency,
|
|
|
+ 'currencyAmount': currencyAmount
|
|
|
})
|
|
|
|
|
|
invoices.append({
|
|
@@ -101,7 +141,8 @@ class PaymentsSales(http.Controller):
|
|
|
'rateSilent': invoice.currency_id.rate_silent,
|
|
|
'thousandsSeparator': invoice.currency_id.thousands_separator,
|
|
|
'decimalSeparator': invoice.currency_id.decimal_separator,
|
|
|
- 'decimalPlaces': invoice.currency_id.decimal_places
|
|
|
+ 'decimalPlaces': invoice.currency_id.decimal_places,
|
|
|
+ 'position': invoice.currency_id.position
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -125,7 +166,8 @@ class PaymentsSales(http.Controller):
|
|
|
Get Journal
|
|
|
'''
|
|
|
def get_journals(self):
|
|
|
- domain =[('active', '=', True),('type', 'in',['bank', 'cash']), ('default_credit_account_id.currency_id', '=', False)]
|
|
|
+ # domain =[('active', '=', True),('type', 'in',['bank', 'cash']), ('default_credit_account_id.currency_id', '=', False)]
|
|
|
+ domain =[('active', '=', True),('type', 'in',['bank', 'cash'])]
|
|
|
paymentsJournals = []
|
|
|
|
|
|
for journal in request.env['account.journal'].search(domain, order="id"):
|
|
@@ -144,7 +186,11 @@ class PaymentsSales(http.Controller):
|
|
|
'name': journal.currency.name,
|
|
|
'displayName': journal.currency.display_name,
|
|
|
'symbol': journal.currency.symbol,
|
|
|
- 'rateSilent': journal.currency.rate_silent
|
|
|
+ 'rateSilent': journal.currency.rate_silent,
|
|
|
+ 'thousandsSeparator':journal.currency.thousands_separator,
|
|
|
+ 'decimalSeparator': journal.currency.decimal_separator,
|
|
|
+ 'decimalPlaces': journal.currency.decimal_places,
|
|
|
+ 'position': journal.currency.position
|
|
|
},
|
|
|
'defaultCreditAccount':{
|
|
|
'id': journal.default_credit_account_id.id,
|
|
@@ -256,17 +302,18 @@ class PaymentsSales(http.Controller):
|
|
|
Create Voucher
|
|
|
'''
|
|
|
def create_voucher(self, period, invoice, company_id, amountPayments, date_server, journalId, move_line_Ids, customerId):
|
|
|
- # get Journal / Currency
|
|
|
+ ## Get Journal
|
|
|
journal_id = request.env['account.journal'].browse(int(journalId))
|
|
|
currency_id = journal_id.default_credit_account_id.currency_id.id or journal_id.default_credit_account_id.company_currency_id.id
|
|
|
+ # currency_rateSilent = journal_id.default_credit_account_id.currency_id.rate_silent or journal_id.default_credit_account_id.company_currency_id.rate_silent
|
|
|
# Get Move Lines
|
|
|
move_line = request.env['account.move.line'].browse(move_line_Ids).sorted(key=lambda r: r.id)
|
|
|
# get customer
|
|
|
customerId = request.env['res.partner'].browse(customerId)
|
|
|
-
|
|
|
+ decimal_precision = request.env['decimal.precision'].precision_get('Account')
|
|
|
# Create Line Voucher
|
|
|
line_cr_ids = []
|
|
|
- amount = float(amountPayments)
|
|
|
+ amount = round(float(amountPayments), decimal_precision)
|
|
|
|
|
|
for line in move_line:
|
|
|
line_cr_ids.append([0, False, {
|
|
@@ -277,25 +324,30 @@ class PaymentsSales(http.Controller):
|
|
|
'amount_original': abs(line.credit or line.debit or 0.0),
|
|
|
'amount_unreconciled': abs(line.amount_residual),
|
|
|
'amount': min(abs(amount), line.amount_residual),
|
|
|
- 'reconcile': line.move_id.date <= line.date_maturity,
|
|
|
+ 'reconcile': True if abs(line.amount_residual) == min(abs(amount), line.amount_residual) else False,
|
|
|
'currency_id': currency_id
|
|
|
}])
|
|
|
amount -= min(abs(amount), line.amount_residual)
|
|
|
|
|
|
+ company_currency = request.env.user.company_id.currency_id
|
|
|
+ currencyVocuher = request.env['res.currency'].browse(currency_id)
|
|
|
+
|
|
|
values = {
|
|
|
'reference': invoice.number,
|
|
|
'type': 'receipt',
|
|
|
'journal_id': journal_id.id,
|
|
|
'company_id': company_id,
|
|
|
'pre_line': True,
|
|
|
- 'amount': float(amountPayments),
|
|
|
+ 'amount': round(float(amountPayments), decimal_precision),
|
|
|
'period_id': period.id,
|
|
|
'date': date_server,
|
|
|
'partner_id': customerId.id,
|
|
|
'account_id': journal_id.default_credit_account_id.id,
|
|
|
'currency_id': currency_id,
|
|
|
- 'line_cr_ids': line_cr_ids
|
|
|
+ 'line_cr_ids': line_cr_ids,
|
|
|
+ 'payment_rate_currency_id': currency_id
|
|
|
}
|
|
|
+
|
|
|
account_voucher = request.env['account.voucher'].create(values)
|
|
|
account_voucher.action_move_line_create()
|
|
|
|
|
@@ -311,6 +363,7 @@ class PaymentsSales(http.Controller):
|
|
|
invoice.write({
|
|
|
'state': 'paid'
|
|
|
})
|
|
|
+ # invoice.confirm_paid()
|
|
|
return invoice
|
|
|
|
|
|
'''
|
|
@@ -371,13 +424,13 @@ class PaymentsSales(http.Controller):
|
|
|
# Get Company
|
|
|
company_id = request.env.user.company_id.id
|
|
|
self.make_info_log('[OK] Getting Company')
|
|
|
- # create voucher
|
|
|
+ # create voucher
|
|
|
voucher = self.create_voucher(period, invoice, company_id, kw.get('amountPayments', 0), date_server, kw.get('journalId'), kw.get('moveLines'), kw.get('customerId'))
|
|
|
self.make_info_log('[OK] creating voucher...')
|
|
|
- # close invoice
|
|
|
+ # close invoice
|
|
|
close_invoice = self.close_invoice(kw.get('invoiceId'))
|
|
|
self.make_info_log('[OK] closing invoice...')
|
|
|
- # Create bank statement
|
|
|
+ # Create bank statement
|
|
|
bank_statement = self.create_bank_statement(date_server, user_id, voucher)
|
|
|
self.make_info_log('[OK] creating bank statement')
|
|
|
|