← Back to team overview

openerp-india team mailing list archive

[Bug 1049184] Re: [Trunk/6.1]Point of sale + Account Voucher error when paying partially

 

Hi,

My colleague Alberto Martin and Me have a posible solution

Here is the class  pos_make_payment().

class pos_make_payment(osv.osv_memory):
    _name = 'pos.make.payment'
    _description = 'Point of Sale Payment'
    def check(self, cr, uid, ids, context=None):
        """Check the order:
        if the order is not paid: continue payment,
        if the order is paid print ticket.
        """
        context = context or {}
        order_obj = self.pool.get('pos.order')
        obj_partner = self.pool.get('res.partner')
        active_id = context and context.get('active_id', False)

        order = order_obj.browse(cr, uid, active_id, context=context)
        amount = order.amount_total - order.amount_paid
        data = self.read(cr, uid, ids, context=context)[0]
        # this is probably a problem of osv_memory as it's not compatible with normal OSV's
        #data['journal'] = data['journal'][0]

        if amount != 0.0:
            order_obj.add_payment(cr, uid, active_id, data, context=context)
        if order_obj.test_paid(cr, uid, [active_id]):
            wf_service = netsvc.LocalService("workflow")
            wf_service.trg_validate(uid, 'pos.order', active_id, 'paid', cr)
            return self.print_report(cr, uid, ids, context=context)

        return self.launch_payment(cr, uid, ids,order,data,
context=context)

    def launch_payment(self, cr, uid, ids,order,data, context=None):
       
        valor = 0.0        
        valor = (order.amount_total - order.amount_paid)-data['amount']
        context['default_amount']= valor
        return {
            'name': _('Paiement'),
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'pos.make.payment',
            'view_id': False,            
            'target': 'new',
            'views': False,
            'type': 'ir.actions.act_window',
            'context' :context
        }

    def print_report(self, cr, uid, ids, context=None):
        active_id = context.get('active_id', [])
        datas = {'ids' : [active_id]}
        return {
            'type': 'ir.actions.report.xml',
            'report_name': 'pos.receipt',
            'datas': datas,
        }

    def _default_journal(self, cr, uid, context=None):
        res = pos_box_entries.get_journal(self, cr, uid, context=context)
        return len(res)>1 and res[1][0] or False

    def _default_amount(self, cr, uid, context=None):
        context = context or {}
        order_obj = self.pool.get('pos.order')
        active_id = context and context.get('active_id', False)
        if active_id:
            order = order_obj.browse(cr, uid, active_id, context=context)
            return order.amount_total- order.amount_paid
        return False   

    _columns = {
        'journal': fields.selection(pos_box_entries.get_journal, "Payment Mode", required=True),
        'amount': fields.float('Amount', digits=(16,2), required= True),
        'payment_name': fields.char('Payment Reference', size=32),
        'payment_date': fields.date('Payment Date', required=True),
    }
    _defaults = {
        'payment_date': time.strftime('%Y-%m-%d %H:%M:%S'),
        'amount': _default_amount,
        'journal': _default_journal
    }

pos_make_payment()

Regard from Guadaltech Soluciones Tecnológicas S.L,  Spain.

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/1049184

Title:
  [Trunk/6.1]Point of sale + Account Voucher error when paying partially

Status in OpenERP Addons (modules):
  Fix Released

Bug description:
  I have OpenERP v6.1 in Ubuntu 12.04 with PostgreSQL. I updated the
  nightly builds, version: OpenERP Server 6.1-20120910-233309.

  - Install "Point of Sale" module.
  - Install "Account Voucher" module.
  - Go to "POS Backend/Configuration/Payment Methods".
  - Create a new Payment Method.
  - Go to "POS Backend/Cash Register Management/Open Cash Registers" and the Open the Cash Register.
  - Go to "POS Backend/Daily Operations/PoS Orders" and create a new one.
  - Create a new Order Line for some amount.
  - Click "Payment" button.
  - Choose the created Payment Method
  - In Amount put a quantity inferior than the amount to pay.
  - Click "Make Payment" and there is a error

  If the error does not appear, try to insert another amount inferior to
  the total amount and click "Make Payment" again.

  The error is the following:

  Client Traceback (most recent call last):
    File "/usr/lib/pymodules/python2.7/openerp/addons/web/common/http.py", line 180, in dispatch
      response["result"] = method(controller, self, **self.params)
    File "/usr/lib/pymodules/python2.7/openerp/addons/web/controllers/main.py", line 1065, in default_get
      return Model.default_get(fields, req.session.eval_context(req.context))
    File "/usr/lib/pymodules/python2.7/openerp/addons/web/common/openerplib/main.py", line 250, in proxy
      args, kw)
    File "/usr/lib/pymodules/python2.7/openerp/addons/web/common/openerplib/main.py", line 117, in proxy
      result = self.connector.send(self.service_name, method, *args)
    File "/usr/lib/pymodules/python2.7/openerp/addons/web/common/http.py", line 608, in send
      raise xmlrpclib.Fault(openerp.tools.exception_to_unicode(e), formatted_info)

  
  Server Traceback (most recent call last):
    File "/usr/lib/pymodules/python2.7/openerp/addons/web/common/http.py", line 593, in send
      return openerp.netsvc.dispatch_rpc(service_name, method, args)
    File "/usr/lib/pymodules/python2.7/openerp/netsvc.py", line 360, in dispatch_rpc
      result = ExportService.getService(service_name).dispatch(method, params)
    File "/usr/lib/pymodules/python2.7/openerp/service/web_services.py", line 586, in dispatch
      res = fn(db, uid, *params)
    File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 167, in execute_kw
      return self.execute(db, uid, obj, method, *args, **kw or {})
    File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 121, in wrapper
      return f(self, dbname, *args, **kwargs)
    File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 176, in execute
      res = self.execute_cr(cr, uid, obj, method, *args, **kw)
    File "/usr/lib/pymodules/python2.7/openerp/osv/osv.py", line 164, in execute_cr
      return getattr(object, method)(cr, uid, *args, **kw)
    File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 1503, in default_get
      defaults[f] = self._defaults[f](self, cr, uid, context)
    File "/usr/lib/pymodules/python2.7/openerp/addons/point_of_sale/wizard/pos_payment.py", line 89, in _default_amount
      return order.amount_total - order.amount_paid
    File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 476, in __getattr__
      return self[name]
    File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 391, in __getitem__
      field_values = self._table.read(self._cr, self._uid, ids, field_names, context=self._context, load="_classic_write")
    File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 3416, in read
      result = self._read_flat(cr, user, select, fields, context, load)
    File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 3527, in _read_flat
      res2 = self._columns[val[0]].get(cr, self, ids, val, user, context=context, values=res)
    File "/usr/lib/pymodules/python2.7/openerp/osv/fields.py", line 1129, in get
      result = self._fnct(obj, cr, uid, ids, name, self._arg, context)
    File "/usr/lib/pymodules/python2.7/openerp/addons/point_of_sale/point_of_sale.py", line 99, in _amount_all
      cur = order.pricelist_id.currency_id
    File "/usr/lib/pymodules/python2.7/openerp/osv/orm.py", line 478, in __getattr__
      raise AttributeError(e)
  AttributeError: 'Field pricelist_id not found in browse_record(pos.order, 2)'

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/1049184/+subscriptions


References