diff --git a/addons/point_of_sale/account_bank_statement.py b/addons/point_of_sale/account_bank_statement.py index 28d3befe3c2..9cf50f6d018 100644 --- a/addons/point_of_sale/account_bank_statement.py +++ b/addons/point_of_sale/account_bank_statement.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- ############################################################################## -# +# # OpenERP, Open Source Management Solution # Copyright (C) 2004-2008 PC Solutions (). All Rights Reserved # Copyright (C) 2004-2010 Tiny SPRL (). @@ -16,21 +16,19 @@ # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . +# along with this program. If not, see . # ############################################################################## -from osv import osv -from osv import fields +from osv import fields, osv class account_journal(osv.osv): - _inherit = 'account.journal' _columns = { 'auto_cash': fields.boolean('Automatic Opening', help="This field authorize the automatic creation of the cashbox"), 'special_journal': fields.boolean('Special Journal', help="Will put all the orders in waiting status till being accepted"), 'check_dtls': fields.boolean('Check Details', help="This field authorize Validation of Cashbox without checking ending details"), - 'journal_users': fields.many2many('res.users','pos_journal_users','journal_id','user_id','Users'), + 'journal_users': fields.many2many('res.users', 'pos_journal_users', 'journal_id', 'user_id', 'Users'), } _defaults = { 'check_dtls': False, @@ -39,7 +37,7 @@ class account_journal(osv.osv): account_journal() class account_cash_statement(osv.osv): - + _inherit = 'account.bank.statement' def _equal_balance(self, cr, uid, cash_id, context=None): @@ -48,12 +46,11 @@ class account_cash_statement(osv.osv): statement = self.browse(cr, uid, cash_id, context=context) if not statement.journal_id.check_dtls: return True - if statement.journal_id.check_dtls and (statement.balance_end != statement.balance_end_cash): return False else: - return True - + return True + def _user_allow(self, cr, uid, statement_id, context=None): if context is None: context = {} @@ -62,12 +59,10 @@ class account_cash_statement(osv.osv): statement = self.browse(cr, uid, statement_id, context=context) for user in statement.journal_id.journal_users: uids.append(user.id) - if uid in uids: res = True - return res - + def _get_cash_open_box_lines(self, cr, uid, context=None): if context is None: context = {} @@ -81,7 +76,7 @@ class account_cash_statement(osv.osv): res.append(dct) res.sort() return res - + def _get_default_cash_close_box_lines(self, cr, uid, context=None): if context is None: context = {} @@ -95,7 +90,7 @@ class account_cash_statement(osv.osv): res.append(dct) res.sort() return res - + account_cash_statement() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/point_of_sale/pos.py b/addons/point_of_sale/pos.py index 6429e21c08d..720fdb465f4 100644 --- a/addons/point_of_sale/pos.py +++ b/addons/point_of_sale/pos.py @@ -20,10 +20,11 @@ ############################################################################## import time -import netsvc -from osv import fields, osv from datetime import datetime from dateutil.relativedelta import relativedelta + +import netsvc +from osv import fields, osv from tools.translate import _ from decimal import Decimal import decimal_precision as dp @@ -39,63 +40,55 @@ class pos_config_journal(osv.osv): } pos_config_journal() + class pos_company_discount(osv.osv): - """ Company Discount and Cashboxes """ - _inherit = 'res.company' _columns = { - 'company_discount': fields.float('Max Discount(%)', digits_compute= dp.get_precision('Point Of Sale')), - 'max_diff': fields.float('Max Difference for Cashboxes', digits_compute= dp.get_precision('Point Of Sale Discount')), - } + 'company_discount': fields.float('Max Discount(%)', digits_compute=dp.get_precision('Point Of Sale')), + 'max_diff': fields.float('Max Difference for Cashboxes', digits_compute=dp.get_precision('Point Of Sale Discount')), + } pos_company_discount() class pos_order(osv.osv): - """ Point of sale gives business owners a convenient way of checking out customers and of recording sales """ _name = "pos.order" _description = "Point of Sale" _order = "date_order, create_date desc" - _order = "date_order desc" - def unlink(self, cr, uid, ids, context=None): for rec in self.browse(cr, uid, ids, context=context): for rec_statement in rec.statement_ids: - if (rec_statement.statement_id and rec_statement.statement_id.state=='confirm') or rec.state=='done': + if (rec_statement.statement_id and rec_statement.statement_id.state == 'confirm') or rec.state == 'done': raise osv.except_osv(_('Invalid action !'), _('Cannot delete a point of sale which is closed or contains confirmed cashboxes!')) return super(pos_order, self).unlink(cr, uid, ids, context=context) def onchange_partner_pricelist(self, cr, uid, ids, part, context=None): - """ Changed price list on_change of partner_id""" - if not part: return {} - pricelist = self.pool.get('res.partner').browse(cr, uid, part).property_product_pricelist.id - return {'value':{'pricelist_id': pricelist}} + pricelist = self.pool.get('res.partner').browse(cr, uid, part, context=context).property_product_pricelist.id + return {'value': {'pricelist_id': pricelist}} def _amount_total(self, cr, uid, ids, field_name, arg, context=None): - """ Calculates amount_tax of order line @param field_names: Names of fields. @return: Dictionary of values """ - cr.execute(""" - SELECT - p.id, - COALESCE(SUM( - l.price_unit*l.qty*(1-(l.discount/100.0)))::decimal(16,2), 0 - ) AS amount - FROM pos_order p - LEFT OUTER JOIN pos_order_line l ON (p.id=l.order_id) - WHERE p.id IN %s GROUP BY p.id """,(tuple(ids),)) + SELECT + p.id, + COALESCE(SUM( + l.price_unit*l.qty*(1-(l.discount/100.0)))::decimal(16,2), 0 + ) AS amount + FROM pos_order p + LEFT OUTER JOIN pos_order_line l ON (p.id = l.order_id) + WHERE p.id IN %s GROUP BY p.id """,(tuple(ids),)) res = dict(cr.fetchall()) - for rec in self.browse(cr, uid, ids, context): + for rec in self.browse(cr, uid, ids, context=context): if rec.partner_id \ and rec.partner_id.property_account_position \ and rec.partner_id.property_account_position.tax_ids: @@ -105,81 +98,75 @@ class pos_order(osv.osv): return res def _get_date_payment2(self, cr, uid, ids, context, *a): - # Todo need to check this function """ Find payment Date - @param field_names: Names of fields. @return: Dictionary of values """ - res = {} - val=None + val = None for order in self.browse(cr, uid, ids): - cr.execute("SELECT date_payment FROM pos_order WHERE id=%s", (order.id,)) + cr.execute("SELECT date_payment FROM pos_order WHERE id = %s", (order.id,)) date_p=cr.fetchone() date_p=date_p and date_p[0] or None if date_p: res[order.id]=date_p return res - cr.execute(" SELECT max(l.date) " + cr.execute(" SELECT MAX(l.date) " " FROM account_move_line l, account_move m, account_invoice i, account_move_reconcile r, pos_order o " - " WHERE i.move_id=m.id AND l.move_id=m.id AND l.reconcile_id=r.id AND o.id=%s AND o.invoice_id=i.id", + " WHERE i.move_id = m.id AND l.move_id = m.id AND l.reconcile_id = r.id AND o.id = %s AND o.invoice_id = i.id", (order.id,)) - val=cr.fetchone() - val= val and val[0] or None + val = cr.fetchone() + val = val and val[0] or None if val: - res[order.id]=val + res[order.id] = val return res def _get_date_payment(self, cr, uid, ids, context, *a): - """ Find Validation Date @return: Dictionary of values """ - res = {} - val=None + val = None for order in self.browse(cr, uid, ids): - cr.execute("SELECT date_validation FROM pos_order WHERE id=%s", (order.id,)) - date_p=cr.fetchone() - date_p=date_p and date_p[0] or None + cr.execute("SELECT date_validation FROM pos_order WHERE id = %s", (order.id,)) + date_p = cr.fetchone() + date_p = date_p and date_p[0] or None if date_p: - res[order.id]=date_p + res[order.id] = date_p return res - discount_allowed=order.company_id.company_discount + discount_allowed = order.company_id.company_discount for line in order.lines: if line.discount > discount_allowed: return {order.id: None } if order.amount_paid == order.amount_total and not date_p: - cr.execute("SELECT MAX(date) FROM account_bank_statement_line WHERE pos_statement_id=%s", (order.id,)) - val=cr.fetchone() - val=val and val[0] or None + cr.execute("SELECT MAX(date) FROM account_bank_statement_line WHERE pos_statement_id = %s", (order.id,)) + val = cr.fetchone() + val = val and val[0] or None if order.invoice_id and order.invoice_id.move_id and not date_p and not val: for o in order.invoice_id.move_id.line_id: - if o.balance==0: - if val %s", (ids[0],comp)) - res2=cr.fetchone() - cr.execute("select journal_id from account_bank_statement_line where pos_statement_id=%s ", (ids[0],)) - res3=cr.fetchall() - list_jrnl=[] + comp = company_disc[0] and company_disc[0].company_id and company_disc[0].company_id.company_discount or 0.0 + cr.execute("SELECT discount FROM pos_order_line WHERE order_id = %s AND discount <= %s", (ids[0], comp)) + res = cr.fetchone() + cr.execute("SELECT discount FROM pos_order_line WHERE order_id = %s AND discount > %s", (ids[0], comp)) + res2 = cr.fetchone() + cr.execute("SELECT journal_id FROM account_bank_statement_line WHERE pos_statement_id = %s ", (ids[0], )) + res3 = cr.fetchall() for r in res3: - cr.execute("select id from account_journal where name= '%s' and special_journal='t'", (r[0],)) - res3=cr.fetchone() - is_special=res3 and res3[0] or None + cr.execute("SELECT id FROM account_journal WHERE name = '%s' AND special_journal = 't'", (r[0], )) + res3 = cr.fetchone() + is_special = res3 and res3[0] or None if is_special: list_jrnl.append(is_special) - r = {} for order in self.browse(cr, uid, ids): - if order.state in ('paid','done','invoiced') and res and not res2 and not len(list_jrnl): + if order.state in ('paid', 'done', 'invoiced') and res and not res2 and not len(list_jrnl): r[order.id] = 'accepted' return r @@ -269,8 +242,8 @@ class pos_order(osv.osv): 'shop_id': fields.many2one('sale.shop', 'Shop', required=True, states={'draft': [('readonly', False)]}, readonly=True), 'date_order': fields.datetime('Date Ordered', readonly=True), - 'date_validation': fields.function(_get_date_payment, method=True, string='Validation Date', type='date', store=True), - 'date_payment': fields.function(_get_date_payment2, method=True, string='Payment Date', type='date', store=True), + 'date_validation': fields.function(_get_date_payment, method=True, string='Validation Date', type='date', store=True), + 'date_payment': fields.function(_get_date_payment2, method=True, string='Payment Date', type='date', store=True), 'date_validity': fields.date('Validity Date', required=True), 'user_id': fields.many2one('res.users', 'Connected Salesman', help="Person who uses the the register. It could be a reliever, a student or an interim employee."), 'user_salesman_id': fields.many2one('res.users', 'Cashier', required=True, help="User who is logged into the system."), @@ -281,15 +254,19 @@ class pos_order(osv.osv): 'amount_return': fields.function(_amount_all, 'Returned', method=True, digits_compute=dp.get_precision('Point Of Sale'), multi='all'), 'lines': fields.one2many('pos.order.line', 'order_id', 'Order Lines', states={'draft': [('readonly', False)]}, readonly=True), 'price_type': fields.selection([ - ('tax_excluded','Tax excluded') - ], 'Price method', required=True), - 'statement_ids': fields.one2many('account.bank.statement.line','pos_statement_id','Payments',states={'draft': [('readonly', False)]},readonly=True), + ('tax_excluded','Tax excluded')], + 'Price method', required=True), + 'statement_ids': fields.one2many('account.bank.statement.line', 'pos_statement_id', 'Payments', states={'draft': [('readonly', False)]}, readonly=True), 'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True, states={'draft': [('readonly', False)]}, readonly=True), - 'partner_id': fields.many2one( 'res.partner', 'Customer', change_default=True, select=1, states={'draft': [('readonly', False)], 'paid': [('readonly', False)]}), - 'state': fields.selection([('draft', 'Quotation'), ('payment', 'Payment'), - ('advance','Advance'), - ('paid', 'Paid'), ('done', 'Done'), ('invoiced', 'Invoiced'), ('cancel', 'Cancel')], - 'State', readonly=True, ), + 'partner_id': fields.many2one('res.partner', 'Customer', change_default=True, select=1, states={'draft': [('readonly', False)], 'paid': [('readonly', False)]}), + 'state': fields.selection([('draft', 'Quotation'), + ('payment', 'Payment'), + ('advance','Advance'), + ('paid', 'Paid'), + ('done', 'Done'), + ('invoiced', 'Invoiced'), + ('cancel', 'Cancel')], + 'State', readonly=True), 'invoice_id': fields.many2one('account.invoice', 'Invoice'), 'account_move': fields.many2one('account.move', 'Account Entry', readonly=True), 'pickings': fields.one2many('stock.picking', 'pos_order', 'Picking', readonly=True), @@ -297,27 +274,23 @@ class pos_order(osv.osv): 'first_name': fields.char('First Name', size=64), 'note': fields.text('Internal Notes'), 'nb_print': fields.integer('Number of Print', readonly=True), - 'sale_journal': fields.many2one('account.journal', 'Journal', required=True, states={'draft': [('readonly', False)]}, readonly=True, ), + 'sale_journal': fields.many2one('account.journal', 'Journal', required=True, states={'draft': [('readonly', False)]}, readonly=True), 'invoice_wanted': fields.boolean('Create Invoice'), - 'note_2': fields.char('Customer Note',size=64), - 'type_rec': fields.char('Type of Receipt',size=64), + 'note_2': fields.char('Customer Note', size=64), + 'type_rec': fields.char('Type of Receipt', size=64), 'remboursed': fields.boolean('Remboursed'), 'contract_number': fields.char('Contract Number', size=512, select=1), 'journal_entry': fields.boolean('Journal Entry'), } - def _select_pricelist(self, cr, uid, context): - + def _select_pricelist(self, cr, uid, context=None): """ To get default pricelist for the order" @param name: Names of fields. @return: pricelist ID """ - pricelist = self.pool.get('product.pricelist').search(cr, uid, [('name', '=', 'Public Pricelist')]) - if pricelist: - return pricelist[0] - else: - return False + pricelist = self.pool.get('product.pricelist').search(cr, uid, [('name', '=', 'Public Pricelist')], context=context) + return pricelist and pricelist[0] or False def _journal_default(self, cr, uid, context=None): """ To get default pricelist for the order" @@ -325,24 +298,21 @@ class pos_order(osv.osv): @return: journal ID """ journal_list = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'cash')]) - if journal_list: - return journal_list[0] - else: - return False + return journal_list and journal_list[0] or False _defaults = { 'user_salesman_id':lambda self, cr, uid, context: uid, 'user_id': lambda self, cr, uid, context: uid, 'sale_manager': lambda self, cr, uid, context: uid, - 'state': lambda *a: 'draft', - 'price_type': lambda *a: 'tax_excluded', + 'state': 'draft', + 'price_type': 'tax_excluded', 'name': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'pos.order'), - 'date_order': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'), + 'date_order': time.strftime('%Y-%m-%d %H:%M:%S'), 'date_validity': lambda *a: (datetime.today() + relativedelta(months=+6)).strftime('%Y-%m-%d'), - 'nb_print': lambda *a: 0, + 'nb_print': 0, 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id, 'sale_journal': _sale_journal_get, - 'invoice_wanted': lambda *a: False, + 'invoice_wanted': False, 'shop_id': _shop_get, 'pricelist_id': _select_pricelist, } @@ -364,22 +334,19 @@ class pos_order(osv.osv): return True def test_paid(self, cr, uid, ids, context=None): - """ Test all amount is paid for this order @return: True """ - for order in self.browse(cr, uid, ids, context): + for order in self.browse(cr, uid, ids, context=context): if order.lines and not order.amount_total: return True if (not order.lines) or (not order.statement_ids) or \ - Decimal(str(order.amount_total))!=Decimal(str(order.amount_paid)): + Decimal(str(order.amount_total)) != Decimal(str(order.amount_paid)): return False return True def _get_qty_differences(self, orders, old_picking): - """check if the customer changed the product quantity """ - order_dict = {} for order in orders: for line in order.lines: @@ -401,9 +368,7 @@ class pos_order(osv.osv): return diff_dict def _split_picking(self, cr, uid, ids, context, old_picking, diff_dict): - """if the customer changes the product quantity, split the picking in two""" - # create a copy of the original picking and adjust the product qty: picking_model = self.pool.get('stock.picking') defaults = { @@ -412,7 +377,7 @@ class pos_order(osv.osv): } new_picking_id = picking_model.copy(cr, uid, old_picking.id, defaults) # state = 'draft' - new_picking = picking_model.browse(cr, uid, new_picking_id, context) + new_picking = picking_model.browse(cr, uid, new_picking_id, context=context) for line in new_picking.move_lines: p_id = line.product_id.id @@ -442,17 +407,16 @@ class pos_order(osv.osv): def create_picking(self, cr, uid, ids, context=None): """Create a picking for each order and validate it.""" - picking_obj = self.pool.get('stock.picking') - property_obj=self.pool.get("ir.property") + property_obj = self.pool.get("ir.property") move_obj=self.pool.get('stock.move') - pick_name=self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.out') - orders = self.browse(cr, uid, ids, context) + pick_name = self.pool.get('ir.sequence').get(cr, uid, 'stock.picking.out') + orders = self.browse(cr, uid, ids, context=context) for order in orders: if not order.picking_id: new = True picking_id = picking_obj.create(cr, uid, { - 'name':pick_name, + 'name': pick_name, 'origin': order.name, 'type': 'out', 'state': 'draft', @@ -461,12 +425,12 @@ class pos_order(osv.osv): 'invoice_state': 'none', 'auto_picking': True, 'pos_order': order.id, - }) - self.write(cr, uid, [order.id], {'picking_id': picking_id}) + }, context=context) + self.write(cr, uid, [order.id], {'picking_id': picking_id}, context=context) else: picking_id = order.picking_id.id - picking_obj.write(cr, uid, [picking_id], {'auto_picking': True}) - picking = picking_obj.browse(cr, uid, [picking_id], context)[0] + picking_obj.write(cr, uid, [picking_id], {'auto_picking': True}, context=context) + picking = picking_obj.browse(cr, uid, [picking_id], context=context)[0] new = False # split the picking (if product quantity has changed): @@ -476,13 +440,13 @@ class pos_order(osv.osv): if new: for line in order.lines: - if line.product_id and line.product_id.type=='service': + if line.product_id and line.product_id.type == 'service': continue - prop_ids = property_obj.search(cr, uid, [('name', '=', 'property_stock_customer')]) - val = property_obj.browse(cr, uid, prop_ids[0]).value_reference - cr.execute("select s.id from stock_location s, stock_warehouse w where w.lot_stock_id=s.id and w.id=%s", (order.shop_id.warehouse_id.id,)) - res=cr.fetchone() - location_id=res and res[0] or None + prop_ids = property_obj.search(cr, uid, [('name', '=', 'property_stock_customer')], context=context) + val = property_obj.browse(cr, uid, prop_ids[0], context=context).value_reference + cr.execute("SELECT s.id FROM stock_location s, stock_warehouse w WHERE w.lot_stock_id = s.id AND w.id = %s", (order.shop_id.warehouse_id.id, )) + res = cr.fetchone() + location_id = res and res[0] or None stock_dest_id = val.id if line.qty < 0: location_id, stock_dest_id = stock_dest_id, location_id @@ -500,37 +464,33 @@ class pos_order(osv.osv): 'state': 'waiting', 'location_id': location_id, 'location_dest_id': stock_dest_id, - }) + }, context=context) wf_service = netsvc.LocalService("workflow") wf_service.trg_validate(uid, 'stock.picking', picking_id, 'button_confirm', cr) - self.pool.get('stock.picking').force_assign(cr, uid, [picking_id], context) + picking_obj.force_assign(cr, uid, [picking_id], context) return True def set_to_draft(self, cr, uid, ids, *args): - """ Changes order state to draft @return: True """ if not len(ids): return False - - self.write(cr, uid, ids, {'state': 'draft'}) - + self.write(cr, uid, ids, {'state': 'draft'}, context=context) wf_service = netsvc.LocalService("workflow") for i in ids: wf_service.trg_create(uid, 'pos.order', i, cr) return True def button_invalidate(self, cr, uid, ids, *args): - """ Check the access for the sale order @return: True """ res_obj = self.pool.get('res.company') try: - part_company=res_obj.browse(cr,uid,uid) and res_obj.browse(cr,uid,uid).parent_id and res_obj.browse(cr,uid,uid).parent_id.id or None + part_company = res_obj.browse(cr, uid, uid) and res_obj.browse(cr, uid, uid).parent_id and res_obj.browse(cr, uid, uid).parent_id.id or None except Exception: raise osv.except_osv(_('Error'), _('You don\'t have enough access to validate this sale!')) if part_company: @@ -538,42 +498,39 @@ class pos_order(osv.osv): return True def cancel_order(self, cr, uid, ids, context=None): - """ Changes order state to cancel @return: True """ - self.write(cr, uid, ids, {'state': 'cancel'}) + self.write(cr, uid, ids, {'state': 'cancel'}, context=context) self.cancel_picking(cr, uid, ids, context=context) return True def add_payment(self, cr, uid, order_id, data, context=None): - """Create a new payment for the order""" - statement_obj= self.pool.get('account.bank.statement') - statementl_obj = self.pool.get('account.bank.statement.line') + statement_line_obj = self.pool.get('account.bank.statement.line') prod_obj = self.pool.get('product.product') - property_obj=self.pool.get('ir.property') - curr_c=self.pool.get('res.users').browse(cr, uid, uid).company_id - curr_company=curr_c.id - order = self.browse(cr, uid, order_id, context) + property_obj = self.pool.get('ir.property') + curr_c = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id + curr_company = curr_c.id + order = self.browse(cr, uid, order_id, context=context) if not order.num_sale and data['num_sale']: - self.write(cr,uid,order_id,{'num_sale': data['num_sale']}) - ids_new=[] + self.write(cr, uid, order_id, {'num_sale': data['num_sale']}, context=context) + ids_new = [] args = { 'amount': data['amount'], } if 'payment_date' in data.keys(): args['date'] = data['payment_date'] if 'payment_name' in data.keys(): - args['name'] = data['payment_name'] + ' ' +order.name + args['name'] = data['payment_name'] + ' ' + order.name account_def = property_obj.get(cr, uid, 'property_account_receivable', 'res.partner', context=context) args['account_id'] = order.partner_id and order.partner_id.property_account_receivable and order.partner_id.property_account_receivable.id or account_def.id or curr_c.account_receivable.id - if data.get('is_acc',False): + if data.get('is_acc', False): args['is_acc'] = data['is_acc'] - args['account_id']= prod_obj.browse(cr,uid, data['product_id']).property_account_income and prod_obj.browse(cr,uid, data['product_id']).property_account_income.id + args['account_id'] = prod_obj.browse(cr, uid, data['product_id'], context=context).property_account_income and prod_obj.browse(cr, uid, data['product_id'], context=context).property_account_income.id if not args['account_id']: - raise osv.except_osv(_('Error'), _('Please provide an account for the product: %s')%(prod_obj.browse(cr,uid, data['product_id']).name)) + raise osv.except_osv(_('Error'), _('Please provide an account for the product: %s')%(prod_obj.browse(cr, uid, data['product_id'], context=context).name)) args['partner_id'] = order.partner_id and order.partner_id.id or None args['ref'] = order.contract_number or None @@ -581,15 +538,15 @@ class pos_order(osv.osv): ('journal_id', '=', data['journal']), ('company_id', '=', curr_company), ('user_id', '=', uid), - ('state', '=', 'open')]) - if len(statement_id)==0: + ('state', '=', 'open')], context=context) + if len(statement_id) == 0: raise osv.except_osv(_('Error !'), _('You have to open at least one cashbox')) if statement_id: - statement_id=statement_id[0] - args['statement_id']= statement_id - args['pos_statement_id']= order_id - args['journal_id']= data['journal'] - statementl_obj.create(cr, uid, args) + statement_id = statement_id[0] + args['statement_id'] = statement_id + args['pos_statement_id'] = order_id + args['journal_id'] = data['journal'] + statement_line_obj.create(cr, uid, args, context=context) ids_new.append(statement_id) wf_service = netsvc.LocalService("workflow") @@ -599,9 +556,7 @@ class pos_order(osv.osv): return statement_id def add_product(self, cr, uid, order_id, product_id, qty, context=None): - """Create a new order line the order""" - line_obj = self.pool.get('pos.order.line') values = self.read(cr, uid, order_id, ['partner_id', 'pricelist_id']) @@ -616,10 +571,9 @@ class pos_order(osv.osv): 'product_id': product_id, 'qty': qty, 'price_unit': price, - }) + }, context=context) wf_service = netsvc.LocalService("workflow") wf_service.trg_write(uid, 'pos.order', order_id, cr) - return order_line_id, price def refund(self, cr, uid, ids, context=None): @@ -627,7 +581,7 @@ class pos_order(osv.osv): clone_list = [] line_obj = self.pool.get('pos.order.line') - for order in self.browse(cr, uid, ids): + for order in self.browse(cr, uid, ids, context=context): clone_id = self.copy(cr, uid, order.id, { 'name': order.name + ' REFUND', 'date_order': time.strftime('%Y-%m-%d'), @@ -636,26 +590,25 @@ class pos_order(osv.osv): 'invoice_id': False, 'nb_print': 0, 'statement_ids': False, - }) + }, context=context) clone_list.append(clone_id) - for clone in self.browse(cr, uid, clone_list): + for clone in self.browse(cr, uid, clone_list, context=context): for order_line in clone.lines: line_obj.write(cr, uid, [order_line.id], { 'qty': -order_line.qty - }) + }, context=context) return clone_list def action_invoice(self, cr, uid, ids, context=None): """Create a invoice of order """ - inv_ref = self.pool.get('account.invoice') inv_line_ref = self.pool.get('account.invoice.line') - product_obj= self.pool.get('product.product') + product_obj = self.pool.get('product.product') inv_ids = [] - for order in self.pool.get('pos.order').browse(cr, uid, ids, context): + for order in self.pool.get('pos.order').browse(cr, uid, ids, context=context): if order.invoice_id: inv_ids.append(order.invoice_id.id) continue @@ -663,12 +616,12 @@ class pos_order(osv.osv): if not order.partner_id: raise osv.except_osv(_('Error'), _('Please provide a partner for the sale.')) - acc= order.partner_id.property_account_receivable.id + acc = order.partner_id.property_account_receivable.id inv = { 'name': 'Invoice from POS: '+order.name, 'origin': order.name, - 'account_id':acc, - 'journal_id':order.sale_journal.id or None, + 'account_id': acc, + 'journal_id': order.sale_journal.id or None, 'type': 'out_invoice', 'reference': order.name, 'partner_id': order.partner_id.id, @@ -677,9 +630,9 @@ class pos_order(osv.osv): inv.update(inv_ref.onchange_partner_id(cr, uid, [], 'out_invoice', order.partner_id.id)['value']) if not inv.get('account_id', None): inv['account_id'] = acc - inv_id = inv_ref.create(cr, uid, inv, context) + inv_id = inv_ref.create(cr, uid, inv, context=context) - self.write(cr, uid, [order.id], {'invoice_id': inv_id, 'state': 'invoiced'}) + self.write(cr, uid, [order.id], {'invoice_id': inv_id, 'state': 'invoiced'}, context=context) inv_ids.append(inv_id) for line in order.lines: inv_line = { @@ -697,10 +650,9 @@ class pos_order(osv.osv): inv_line['discount'] = line.discount inv_line['account_id'] = acc inv_line['name'] = inv_name - inv_line['invoice_line_tax_id'] = ('invoice_line_tax_id' in inv_line)\ and [(6, 0, inv_line['invoice_line_tax_id'])] or [] - inv_line_ref.create(cr, uid, inv_line, context) + inv_line_ref.create(cr, uid, inv_line, context=context) for i in inv_ids: wf_service = netsvc.LocalService("workflow") @@ -708,9 +660,7 @@ class pos_order(osv.osv): return inv_ids def create_account_move(self, cr, uid, ids, context=None): - """Create a account move line of order """ - account_move_obj = self.pool.get('account.move') account_move_line_obj = self.pool.get('account.move.line') account_period_obj = self.pool.get('account.period') @@ -720,9 +670,9 @@ class pos_order(osv.osv): period = account_period_obj.find(cr, uid, context=context)[0] for order in self.browse(cr, uid, ids, context=context): - curr_c =res_obj.browse(cr, uid, uid).company_id + curr_c = res_obj.browse(cr, uid, uid).company_id comp_id = res_obj.browse(cr, order.user_id.id, order.user_id.id).company_id - comp_id=comp_id and comp_id.id or False + comp_id = comp_id and comp_id.id or False to_reconcile = [] group_tax = {} account_def = property_obj.get(cr, uid, 'property_account_receivable', 'res.partner', context=context).id @@ -737,10 +687,9 @@ class pos_order(osv.osv): # Create an move for each order line for line in order.lines: - tax_amount = 0 taxes = [t for t in line.product_id.taxes_id] - if order.price_type=='tax_excluded': + if order.price_type == 'tax_excluded': computed_taxes = account_tax_obj.compute_all( cr, uid, taxes, line.price_unit, line.qty)['taxes'] else: @@ -757,7 +706,7 @@ class pos_order(osv.osv): group_tax[group_key] += round(tax['amount'], 2) else: group_tax[group_key] = round(tax['amount'], 2) - if order.price_type!='tax_excluded': + if order.price_type != 'tax_excluded': amount = line.price_subtotal - tax_amount else: amount = line.price_subtotal @@ -775,7 +724,6 @@ class pos_order(osv.osv): 'account defined for this product: "%s" (id:%d)') \ % (line.product_id.name, line.product_id.id, )) - # Empty the tax list as long as there is no tax code: tax_code_id = False tax_amount = 0 @@ -797,7 +745,7 @@ class pos_order(osv.osv): 'date': order.date_order[:10], 'ref': order.contract_number or order.name, 'quantity': line.qty, - 'product_id':line.product_id.id, + 'product_id': line.product_id.id, 'move_id': move_id, 'account_id': income_account, 'company_id': comp_id, @@ -821,7 +769,7 @@ class pos_order(osv.osv): continue account_move_line_obj.create(cr, uid, { - 'name': "bb"+order.name, + 'name': "bb" + order.name, 'date': order.date_order[:10], 'ref': order.contract_number or order.name, 'product_id':line.product_id.id, @@ -842,13 +790,13 @@ class pos_order(osv.osv): (tax_code_pos, base_code_pos, account_pos)= (0, 1, 2) for key, amount in group_tax.items(): account_move_line_obj.create(cr, uid, { - 'name':"cc"+order.name, + 'name': "cc" + order.name, 'date': order.date_order[:10], 'ref': order.contract_number or order.name, 'move_id': move_id, 'company_id': comp_id, 'quantity': line.qty, - 'product_id':line.product_id.id, + 'product_id': line.product_id.id, 'account_id': key[account_pos], 'credit': ((amount>0) and amount) or 0.0, 'debit': ((amount<0) and -amount) or 0.0, @@ -860,15 +808,15 @@ class pos_order(osv.osv): # counterpart to_reconcile.append(account_move_line_obj.create(cr, uid, { - 'name': "dd"+order.name, + 'name': "dd" + order.name, 'date': order.date_order[:10], 'ref': order.contract_number or order.name, 'move_id': move_id, 'company_id': comp_id, 'account_id': order_account, - 'credit': ((order.amount_total<0) and -order.amount_total)\ + 'credit': ((order.amount_total < 0) and -order.amount_total)\ or 0.0, - 'debit': ((order.amount_total>0) and order.amount_total)\ + 'debit': ((order.amount_total > 0) and order.amount_total)\ or 0.0, 'journal_id': order.sale_journal.id, 'period_id': period, @@ -882,7 +830,6 @@ class pos_order(osv.osv): _('There is no receivable account defined for this journal:'\ ' "%s" (id:%d)') % (order.sale_journal.name, order.sale_journal.id, )) for payment in order.statement_ids: - # Create one entry for the payment if payment.is_acc: continue @@ -903,23 +850,24 @@ class pos_order(osv.osv): }) account_move_line_obj.copy(cr, uid, s.id, { 'statement_id': False, - 'account_id':order_account + 'account_id': order_account }) - self.write(cr,uid,order.id,{'state':'done'}) + self.write(cr, uid, order.id, {'state':'done'}, context=context) return True def cancel_picking(self, cr, uid, ids, context=None): + stock_picking_obj = self.pool.get('stock.picking') for order in self.browse(cr, uid, ids, context=context): for picking in order.pickings: - self.pool.get('stock.picking').unlink(cr, uid, [picking.id], context) + stock_picking_obj.unlink(cr, uid, [picking.id], context=context) return True def action_payment(self, cr, uid, ids, context=None): vals = {'state': 'payment'} - sequence_obj=self.pool.get('ir.sequence') - for pos in self.browse(cr, uid, ids): + sequence_obj = self.pool.get('ir.sequence') + for pos in self.browse(cr, uid, ids, context=context): create_contract_nb = False for line in pos.lines: if line.product_id.product_type == 'MD': @@ -927,21 +875,21 @@ class pos_order(osv.osv): break if create_contract_nb: seq = sequence_obj.get(cr, uid, 'pos.user_%s' % pos.user_salesman_id.login) - vals['contract_number'] ='%s-%s' % (pos.user_salesman_id.login, seq) - self.write(cr, uid, ids, vals) + vals['contract_number'] = '%s-%s' % (pos.user_salesman_id.login, seq) + self.write(cr, uid, ids, vals, context=context) def action_paid(self, cr, uid, ids, context=None): if not context: context = {} - if context.get('flag',False): + if context.get('flag', False): self.create_picking(cr, uid, ids, context=None) - self.write(cr, uid, ids, {'state': 'paid'}) + self.write(cr, uid, ids, {'state': 'paid'}, context=context) else: - context['flag']=True + context['flag'] = True return True def action_cancel(self, cr, uid, ids, context=None): - self.write(cr, uid, ids, {'state': 'cancel'}) + self.write(cr, uid, ids, {'state': 'cancel'}, context=context) return True def action_done(self, cr, uid, ids, context=None): @@ -951,12 +899,12 @@ class pos_order(osv.osv): return True def compute_state(self, cr, uid, id): - cr.execute("select act.id, act.name from wkf_activity act " - "inner join wkf_workitem item on act.id=item.act_id " - "inner join wkf_instance inst on item.inst_id=inst.id " - "inner join wkf on inst.wkf_id=wkf.id " - "where wkf.osv='pos.order' and inst.res_id=%s " - "order by act.name", (id,)) + cr.execute("SELECT act.id, act.name FROM wkf_activity act " + "INNER JOIN wkf_workitem item ON act.id = item.act_id " + "INNER JOIN wkf_instance inst ON item.inst_id = inst.id " + "INNER JOIN wkf ON inst.wkf_id = wkf.id " + "WHERE wkf.osv = 'pos.order' AND inst.res_id = %s " + "ORDER BY act.name", (id, )) return [name for id, name in cr.fetchall()] pos_order() @@ -964,7 +912,7 @@ pos_order() class account_bank_statement(osv.osv): _inherit = 'account.bank.statement' _columns= { - 'user_id': fields.many2one('res.users',ondelete='cascade',string='User', readonly=True), + 'user_id': fields.many2one('res.users', ondelete='cascade', string='User', readonly=True), } _defaults = { 'user_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).id @@ -980,9 +928,9 @@ class account_bank_statement_line(osv.osv): return res _columns= { 'journal_id': fields.function(_get_statement_journal, method=True,store=True, string='Journal', type='char', size=64), - 'am_out':fields.boolean("To count"), - 'is_acc':fields.boolean("Is accompte"), - 'pos_statement_id': fields.many2one('pos.order',ondelete='cascade'), + 'am_out': fields.boolean("To count"), + 'is_acc': fields.boolean("Is accompte"), + 'pos_statement_id': fields.many2one('pos.order', ondelete='cascade'), } account_bank_statement_line() @@ -990,18 +938,18 @@ class pos_order_line(osv.osv): _name = "pos.order.line" _description = "Lines of Point of Sale" - def _get_amount(self, cr, uid, ids, field_name, arg, context): + def _get_amount(self, cr, uid, ids, field_name, arg, context=None): res = {} - for line in self.browse(cr, uid, ids): + for line in self.browse(cr, uid, ids, context=context): price = self.price_by_product(cr, uid, ids, line.order_id.pricelist_id.id, line.product_id.id, line.qty, line.order_id.partner_id.id) - res[line.id]=price + res[line.id] = price return res - def _amount_line_ttc(self, cr, uid, ids, field_name, arg, context): + def _amount_line_ttc(self, cr, uid, ids, field_name, arg, context=None): res = dict.fromkeys(ids, 0.0) account_tax_obj = self.pool.get('account.tax') self.price_by_product_multi(cr, uid, ids) - for line in self.browse(cr, uid, ids): + for line in self.browse(cr, uid, ids, context=context): tax_amount = 0.0 taxes = [t for t in line.product_id.taxes_id] if line.qty == 0.0: @@ -1009,27 +957,25 @@ class pos_order_line(osv.osv): computed_taxes = account_tax_obj.compute_all(cr, uid, taxes, line.price_unit, line.qty)['taxes'] for tax in computed_taxes: tax_amount += tax['amount'] - if line.discount!=0.0: + if line.discount != 0.0: res[line.id] = line.price_unit * line.qty * (1 - (line.discount or 0.0) / 100.0) else: - res[line.id]=line.price_unit*line.qty + res[line.id] = line.price_unit*line.qty res[line.id] = res[line.id] + tax_amount return res - def _amount_line(self, cr, uid, ids, field_name, arg, context): + def _amount_line(self, cr, uid, ids, field_name, arg, context=None): res = {} - self.price_by_product_multi(cr, uid, ids) - for line in self.browse(cr, uid, ids): + for line in self.browse(cr, uid, ids, context=context): if line.discount!=0.0: res[line.id] = line.price_unit * line.qty * (1 - (line.discount or 0.0) / 100.0) else: - res[line.id]=line.price_unit*line.qty + res[line.id] = line.price_unit * line.qty return res def _amount_line_all(self, cr, uid, ids, field_names, arg, context): res = dict([(i, {}) for i in ids]) - account_tax_obj = self.pool.get('account.tax') self.price_by_product_multi(cr, uid, ids) @@ -1059,9 +1005,7 @@ class pos_order_line(osv.osv): def price_by_product_multi(self, cr, uid, ids, context=None): if context is None: context = {} - res = {}.fromkeys(ids, 0.0) - lines = self.browse(cr, uid, ids, context=context) pricelist_ids = [line.order_id.pricelist_id.id for line in lines] @@ -1105,10 +1049,10 @@ class pos_order_line(osv.osv): raise osv.except_osv(_('No Pricelist !'), _('You have to select a pricelist in the sale form !\n' \ 'Please set one before choosing a product.')) - p_obj = self.pool.get('product.product').browse(cr,uid,[product_id])[0] + p_obj = self.pool.get('product.product').browse(cr, uid, [product_id])[0] uom_id = p_obj.uom_po_id.id price = self.pool.get('product.pricelist').price_get(cr, uid, - [pricelist], product_id, qty or 1.0, partner_id,{'uom': uom_id})[pricelist] + [pricelist], product_id, qty or 1.0, partner_id, {'uom': uom_id})[pricelist] unit_price=price or p_obj.list_price if unit_price is False: raise osv.except_osv(_('No valid pricelist line found !'), @@ -1119,38 +1063,38 @@ class pos_order_line(osv.osv): def onchange_product_id(self, cr, uid, ids, pricelist, product_id, qty=0, partner_id=False): price = self.price_by_product(cr, uid, ids, pricelist, product_id, qty, partner_id) - self.write(cr,uid,ids,{'price_unit':price}) + self.write(cr, uid, ids, {'price_unit':price}) pos_stot = (price * qty) - return {'value': {'price_unit': price,'price_subtotal_incl': pos_stot}} + return {'value': {'price_unit': price, 'price_subtotal_incl': pos_stot}} - def onchange_subtotal(self, cr, uid, ids, discount, price, pricelist,qty,partner_id, product_id,*a): + def onchange_subtotal(self, cr, uid, ids, discount, price, pricelist, qty,partner_id, product_id, *a): prod_obj = self.pool.get('product.product') price_f = self.price_by_product(cr, uid, ids, pricelist, product_id, qty, partner_id) - prod_id='' + prod_id = '' if product_id: - prod_id=prod_obj.browse(cr,uid,product_id).disc_controle - disc=0.0 - if (disc != 0.0 or prod_id) and price_f>0: - disc=100-(price/price_f*100) - return {'value':{'discount':disc, 'price_unit':price_f}} + prod_id = prod_obj.browse(cr, uid, product_id).disc_controle + disc = 0.0 + if (disc != 0.0 or prod_id) and price_f > 0: + disc = 100 - (price/price_f*100) + return {'value': {'discount': disc, 'price_unit': price_f}} return {} - def onchange_dis(self, cr, uid,ids, qty, price_subtotal_incl, discount,*a): + def onchange_dis(self, cr, uid, ids, qty, price_subtotal_incl, discount, *a): price_sub = price_subtotal_incl - sub_total_discount = price_sub-(price_subtotal_incl*(discount*0.01)) - return {'value': {'price_subtotal_incl':sub_total_discount}} + sub_total_discount = price_sub - (price_subtotal_incl*(discount*0.01)) + return {'value': {'price_subtotal_incl': sub_total_discount}} - def onchange_ded(self, cr, uid,ids, val_ded,price_u,*a): + def onchange_ded(self, cr, uid, ids, val_ded, price_u, *a): res_obj = self.pool.get('res.users') - comp = res_obj.browse(cr,uid,uid).company_id.company_discount or 0.0 - val=0.0 + comp = res_obj.browse(cr, uid, uid).company_id.company_discount or 0.0 + val = 0.0 if val_ded and price_u: - val=100.0*val_ded/price_u + val=100.0 * val_ded / price_u if val > comp: - return {'value': {'discount':val, 'notice':'' }} - return {'value': {'discount':val}} + return {'value': {'discount': val, 'notice': '' }} + return {'value': {'discount': val}} - def onchange_discount(self, cr, uid,ids, discount,price,*a): + def onchange_discount(self, cr, uid, ids, discount, price, *a): pos_order = self.pool.get('pos.order.line') res_obj = self.pool.get('res.users') company_disc = pos_order.browse(cr,uid,ids) @@ -1161,11 +1105,11 @@ class pos_order_line(osv.osv): comp= company_disc[0] and company_disc[0].order_id.company_id and company_disc[0].order_id.company_id.company_discount or 0.0 if discount > comp : - return {'value': {'notice':'','price_ded':price*discount*0.01 or 0.0 }} + return {'value': {'notice': '', 'price_ded': price * discount * 0.01 or 0.0 }} else: - return {'value': {'notice':'Minimum Discount','price_ded':price*discount*0.01 or 0.0 }} + return {'value': {'notice': 'Minimum Discount', 'price_ded': price * discount * 0.01 or 0.0 }} else : - return {'value': {'notice':'No Discount', 'price_ded':price*discount*0.01 or 0.0}} + return {'value': {'notice': 'No Discount', 'price_ded': price * discount * 0.01 or 0.0}} def onchange_qty(self, cr, uid, ids, discount, qty, price, context=None): subtotal = qty * price @@ -1175,12 +1119,12 @@ class pos_order_line(osv.osv): _columns = { 'name': fields.char('Line Description', size=512), - 'company_id':fields.many2one('res.company', 'Company', required=True), + 'company_id': fields.many2one('res.company', 'Company', required=True), 'notice': fields.char('Discount Notice', size=128, required=True), 'serial_number': fields.char('Serial Number', size=128), 'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok', '=', True)], required=True, change_default=True), 'price_unit': fields.function(_get_amount, method=True, string='Unit Price', store=True), - 'price_ded': fields.float('Discount(Amount)',digits_compute=dp.get_precision('Point Of Sale')), + 'price_ded': fields.float('Discount(Amount)', digits_compute=dp.get_precision('Point Of Sale')), 'qty': fields.float('Quantity'), 'qty_rfd': fields.float('Refunded Quantity'), 'price_subtotal': fields.function(_amount_line_all, method=True, multi='pos_order_line_amount', string='Subtotal w/o Tax'), @@ -1201,17 +1145,17 @@ class pos_order_line(osv.osv): def create(self, cr, user, vals, context=None): if vals.get('product_id'): - return super(pos_order_line, self).create(cr, user, vals, context) + return super(pos_order_line, self).create(cr, user, vals, context=context) return False def write(self, cr, user, ids, values, context=None): if 'product_id' in values and not values['product_id']: return False - return super(pos_order_line, self).write(cr, user, ids, values, context) + return super(pos_order_line, self).write(cr, user, ids, values, context=context) def _scan_product(self, cr, uid, ean, qty, order): # search pricelist_id - product_obj=self.pool.get('product.product') + product_obj = self.pool.get('product.product') pricelist_id = self.pool.get('pos.order').read(cr, uid, [order], ['pricelist_id'] ) if not pricelist_id: return False @@ -1223,11 +1167,11 @@ class pos_order_line(osv.osv): return False # search price product - product =product_obj.read(cr, uid, product_id) + product = product_obj.read(cr, uid, product_id) product_name = product[0]['name'] price = self.price_by_product(cr, uid, 0, pricelist_id[0]['pricelist_id'][0], product_id[0], 1) - order_line_ids = self.search(cr, uid, [('name','=',product_name),('order_id','=',order)]) + order_line_ids = self.search(cr, uid, [('name', '=', product_name), ('order_id', '=' ,order)]) if order_line_ids: new_line = False order_line_id = order_line_ids[0] @@ -1253,7 +1197,7 @@ class pos_order_line(osv.osv): raise osv.except_osv(_('Error'), _('Modify line failed !')) line_id = order_line_id - price_line = float(qty)*float(price) + price_line = float(qty) * float(price) return { 'name': product_name, 'product_id': product_id[0], @@ -1273,12 +1217,11 @@ class product_product(osv.osv): 'disc_controle': fields.boolean('Discount Control'), } _defaults = { - 'disc_controle': lambda *a: True, + 'disc_controle': True, } product_product() class stock_picking(osv.osv): - _inherit = 'stock.picking' _columns = { 'pos_order': fields.many2one('pos.order', 'Pos order'), diff --git a/addons/point_of_sale/wizard/all_closed_cashbox_of_the_day.py b/addons/point_of_sale/wizard/all_closed_cashbox_of_the_day.py index 58f78902a14..3f561848edf 100644 --- a/addons/point_of_sale/wizard/all_closed_cashbox_of_the_day.py +++ b/addons/point_of_sale/wizard/all_closed_cashbox_of_the_day.py @@ -19,38 +19,32 @@ # ############################################################################## -import netsvc -from osv import osv,fields -from tools.translate import _ import time +import netsvc +from osv import osv, fields +from tools.translate import _ + class all_closed_cashbox_of_the_day(osv.osv_memory): _name = 'all.closed.cashbox.of.the.day' _description = 'All closed cashbox of the day' - _columns = { - - } - def print_report(self, cr, uid, ids, context=None): - """ To get the date and print the report - @param self: The object pointer. @param cr: A database cursor @param uid: ID of the user currently logged in @param context: A standard dictionary @return : retrun report """ - datas = {'ids' : context.get('active_ids',[])} + datas = {'ids': context.get('active_ids', [])} res = {} datas['form'] = res - return { - 'type' : 'ir.actions.report.xml', - 'report_name':'all.closed.cashbox.of.the.day', - 'datas' : datas, + 'type': 'ir.actions.report.xml', + 'report_name': 'all.closed.cashbox.of.the.day', + 'datas': datas, } all_closed_cashbox_of_the_day() diff --git a/addons/point_of_sale/wizard/pos_add_product.py b/addons/point_of_sale/wizard/pos_add_product.py index 5735d2976a4..601c3d3f305 100644 --- a/addons/point_of_sale/wizard/pos_add_product.py +++ b/addons/point_of_sale/wizard/pos_add_product.py @@ -32,10 +32,10 @@ class add_product(osv.osv_memory): 'quantity': fields.float('Quantity', required=True), } _defaults = { - 'quantity': lambda *a: 1, + 'quantity': 1, } - def select_product(self, cr, uid, ids, context): + def select_product(self, cr, uid, ids, context=None): """ To get the product and quantity and add in order . @param self: The object pointer. @@ -44,13 +44,14 @@ class add_product(osv.osv_memory): @param context: A standard dictionary @return : Return the add product form again for adding more product """ + if context is None: + context = {} this = self.browse(cr, uid, ids[0], context=context) record_id = context and context.get('active_id', False) assert record_id, _('Active ID is not found') if record_id: order_obj = self.pool.get('pos.order') order_obj.add_product(cr, uid, record_id, this.product_id.id, this.quantity, context=context) - return { 'name': _('Add Product'), 'view_type': 'form', @@ -61,34 +62,36 @@ class add_product(osv.osv_memory): 'views': False, 'type': 'ir.actions.act_window', } - def close_action(self, cr, uid, ids, context): + + def close_action(self, cr, uid, ids, context=None): """ To get the product and Make the payment . @param self: The object pointer. @param cr: A database cursor @param uid: ID of the user currently logged in @param context: A standard dictionary - @return : Return the Make Payment + @return : Return the Make Payment """ - + if context is None: + context = {} record_id = context and context.get('active_id', False) order_obj= self.pool.get('pos.order') - obj=order_obj.browse(cr, uid, record_id) - order_obj.write(cr, uid, [record_id], {'state':'done'}) + obj = order_obj.browse(cr, uid, record_id, context=context) + order_obj.write(cr, uid, [record_id], {'state': 'done'}, context=context) if obj.amount_total != obj.amount_paid: return { - 'name': _('Make Payment'), - 'context ':context and context.get('active_id', False), - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'pos.make.payment', - 'view_id': False, - 'target': 'new', - 'views': False, - 'type': 'ir.actions.act_window', - + 'name': _('Make Payment'), + 'context': context and context.get('active_id', False), + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'pos.make.payment', + 'view_id': False, + 'target': 'new', + 'views': False, + 'type': 'ir.actions.act_window', } - return {} + return {} + add_product() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/point_of_sale/wizard/pos_box_entries.py b/addons/point_of_sale/wizard/pos_box_entries.py index 103e49be62d..d9fd5a61573 100644 --- a/addons/point_of_sale/wizard/pos_box_entries.py +++ b/addons/point_of_sale/wizard/pos_box_entries.py @@ -19,30 +19,31 @@ # ############################################################################## -from osv import osv, fields import time + +from osv import osv, fields from tools.translate import _ -def get_journal(self, cr, uid, context): +def get_journal(self, cr, uid, context=None): """ - Make the selection list of Cash Journal . - @param self: The object pointer. - @param cr: A database cursor - @param uid: ID of the user currently logged in - @param context: A standard dictionary - @return :Return the list of journal + Make the selection list of Cash Journal . + @param self: The object pointer. + @param cr: A database cursor + @param uid: ID of the user currently logged in + @param context: A standard dictionary + @return :Return the list of journal """ - obj = self.pool.get('account.journal') + journal_obj = self.pool.get('account.journal') statement_obj = self.pool.get('account.bank.statement') - cr.execute("SELECT DISTINCT journal_id from pos_journal_users where user_id=%s order by journal_id", (uid,)) + cr.execute("SELECT DISTINCT journal_id FROM pos_journal_users WHERE user_id = %s ORDER BY journal_id", (uid, )) j_ids = map(lambda x1: x1[0], cr.fetchall()) - ids = obj.search(cr, uid, [('type', '=', 'cash'), ('id', 'in', j_ids)]) - obj_ids= statement_obj.search(cr, uid, [('state', '!=', 'confirm'), ('user_id', '=', uid), ('journal_id', 'in', ids)]) - res_obj = obj.read(cr, uid, ids, ['journal_id'], context) - res_obj = [(r1['id'])for r1 in res_obj] - res = statement_obj.read(cr, uid, obj_ids, ['journal_id'], context) + ids = journal_obj.search(cr, uid, [('type', '=', 'cash'), ('id', 'in', j_ids)], context=context) + obj_ids = statement_obj.search(cr, uid, [('state', '!=', 'confirm'), ('user_id', '=', uid), ('journal_id', 'in', ids)], context=context) + res_obj = journal_obj.read(cr, uid, ids, ['journal_id'], context=context) + res_obj = [(r1['id']) for r1 in res_obj] + res = statement_obj.read(cr, uid, obj_ids, ['journal_id'], context=context) res = [(r['journal_id']) for r in res] res.insert(0, ('', '')) return res @@ -51,10 +52,7 @@ class pos_box_entries(osv.osv_memory): _name = 'pos.box.entries' _description = 'Pos Box Entries' - - def _get_income_product(self, cr, uid, context): - """ Make the selection list of purchasing products. @param self: The object pointer.