Commit bc2a0f31 by Etienne Freiss

develop

parent 59273361
...@@ -4,3 +4,4 @@ from . import pos_config ...@@ -4,3 +4,4 @@ from . import pos_config
from . import pos_order from . import pos_order
from . import product_category from . import product_category
from . import product_template from . import product_template
from . import account_bank_statement_line
# Copyright (C) 2020 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models
class AccountBankStatementLine(models.Model):
_inherit = 'account.bank.statement.line'
statement_note = fields.Char(
string="Number ID of the meal voucher")
...@@ -3,7 +3,11 @@ ...@@ -3,7 +3,11 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models from openerp import models
import time
from datetime import datetime
import uuid
from openerp import tools
from openerp.osv import fields
class PosOrder(models.Model): class PosOrder(models.Model):
_inherit = 'pos.order' _inherit = 'pos.order'
...@@ -13,3 +17,69 @@ class PosOrder(models.Model): ...@@ -13,3 +17,69 @@ class PosOrder(models.Model):
res["statement_note"] = ui_paymentline.get("statement_note", False) res["statement_note"] = ui_paymentline.get("statement_note", False)
return res return res
def add_payment(self, cr, uid, order_id, data, context=None):
# From odoo/addons/point_of_sale/point_of_sale.py line 1107
"""Create a new payment for the order"""
context = dict(context or {})
statement_line_obj = self.pool.get('account.bank.statement.line')
property_obj = self.pool.get('ir.property')
order = self.browse(cr, uid, order_id, context=context)
date = data.get('payment_date', time.strftime('%Y-%m-%d'))
if len(date) > 10:
timestamp = datetime.strptime(date, tools.DEFAULT_SERVER_DATETIME_FORMAT)
ts = fields.datetime.context_timestamp(cr, uid, timestamp, context)
date = ts.strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
args = {
'amount': data['amount'],
'date': date,
'name': order.name + ': ' + (data.get('payment_name', '') or ''),
'partner_id': order.partner_id and self.pool.get("res.partner")._find_accounting_partner(order.partner_id).id or False,
}
journal_id = data.get('journal', False)
statement_id = data.get('statement_id', False)
assert journal_id or statement_id, "No statement_id or journal_id passed to the method!"
journal = self.pool['account.journal'].browse(cr, uid, journal_id, context=context)
# use the company of the journal and not of the current user
company_cxt = dict(context, force_company=journal.company_id.id)
account_def = property_obj.get(cr, uid, 'property_account_receivable_id', 'res.partner', context=company_cxt)
args['account_id'] = (order.partner_id and order.partner_id.property_account_receivable_id \
and order.partner_id.property_account_receivable_id.id) or (account_def and account_def.id) or False
if not args['account_id']:
if not args['partner_id']:
msg = _('There is no receivable account defined to make payment.')
else:
msg = _('There is no receivable account defined to make payment for the partner: "%s" (id:%d).') % (order.partner_id.name, order.partner_id.id,)
raise UserError(msg)
context.pop('pos_session_id', False)
for statement in order.session_id.statement_ids:
if statement.id == statement_id:
journal_id = statement.journal_id.id
break
elif statement.journal_id.id == journal_id:
statement_id = statement.id
break
if not statement_id:
raise UserError(_('You have to open at least one cashbox.'))
statement_note = ''
if data['statement_note'] != '':
statement_note = data['statement_note']
args.update({
'statement_id': statement_id,
'pos_statement_id': order_id,
'journal_id': journal_id,
'ref': order.session_id.name,
'statement_note': statement_note,
})
statement_line_obj.create(cr, uid, args, context=context)
return statement_id
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment