2010-01-18 08:38:26 +00:00
# -*- encoding: utf-8 -*-
2008-08-24 14:45:43 +00:00
##############################################################################
2009-12-29 12:49:21 +00:00
#
2009-01-30 10:37:24 +00:00
# OpenERP, Open Source Management Solution
2010-01-18 08:38:26 +00:00
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
2008-11-03 19:18:56 +00:00
#
# This program is free software: you can redistribute it and/or modify
2010-01-18 08:38:26 +00:00
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
2008-11-03 19:18:56 +00:00
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2010-01-18 08:38:26 +00:00
# GNU General Public License for more details.
2008-11-03 19:18:56 +00:00
#
2009-10-14 11:15:34 +00:00
# You should have received a copy of the GNU Affero General Public License
2009-12-29 12:49:21 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2008-08-24 14:45:43 +00:00
#
##############################################################################
import time
import netsvc
from osv import fields , osv
from mx import DateTime
2008-12-20 19:33:44 +00:00
from tools . translate import _
2009-06-16 08:10:56 +00:00
from decimal import Decimal
2010-01-18 08:38:26 +00:00
import tools
import re
2010-04-26 10:30:38 +00:00
import decimal_precision as dp
2008-08-24 14:45:43 +00:00
class pos_config_journal ( osv . osv ) :
2010-04-08 09:20:32 +00:00
""" Point of Sale journal configuration """
2008-08-24 14:45:43 +00:00
_name = ' pos.config.journal '
2010-05-19 18:32:32 +00:00
_description = " Journal Configuration "
2008-08-24 14:45:43 +00:00
_columns = {
' name ' : fields . char ( ' Description ' , size = 64 ) ,
' code ' : fields . char ( ' Code ' , size = 64 ) ,
' journal_id ' : fields . many2one ( ' account.journal ' , " Journal " )
}
pos_config_journal ( )
2010-01-18 08:38:26 +00:00
class pos_company_discount ( osv . osv ) :
2010-04-08 09:20:32 +00:00
""" Company Discount and Cashboxes """
2010-01-18 08:38:26 +00:00
_inherit = ' res.company '
_columns = {
2010-04-26 10:30:38 +00:00
' 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 ' ) ) ,
2010-01-18 08:38:26 +00:00
}
pos_company_discount ( )
2008-08-24 14:45:43 +00:00
class pos_order ( osv . osv ) :
2010-04-08 09:20:32 +00:00
""" Point of sale gives business owners a convenient way of checking out customers
and of recording sales """
2008-08-24 14:45:43 +00:00
_name = " pos.order "
_description = " Point of Sale "
_order = " date_order, create_date desc "
2010-01-18 08:38:26 +00:00
_order = " date_order desc "
2008-08-24 14:45:43 +00:00
2010-04-08 09:20:32 +00:00
2008-12-20 09:43:37 +00:00
def unlink ( self , cr , uid , ids , context = { } ) :
2010-04-08 09:20:32 +00:00
2008-12-20 09:43:37 +00:00
for rec in self . browse ( cr , uid , ids , context = context ) :
2010-01-18 08:38:26 +00:00
for rec_statement in rec . statement_ids :
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! ' ) )
2008-12-20 09:43:37 +00:00
return super ( pos_order , self ) . unlink ( cr , uid , ids , context = context )
def onchange_partner_pricelist ( self , cr , uid , ids , part , context = { } ) :
2010-04-08 09:20:32 +00:00
""" Changed price list on_change of partner_id """
2008-12-20 09:43:37 +00:00
if not part :
return { }
2009-01-30 10:37:24 +00:00
pricelist = self . pool . get ( ' res.partner ' ) . browse ( cr , uid , part ) . property_product_pricelist . id
2010-01-18 08:38:26 +00:00
return { ' value ' : { ' pricelist_id ' : pricelist } }
2008-08-24 14:45:43 +00:00
def _amount_total ( self , cr , uid , ids , field_name , arg , context ) :
2010-04-08 09:20:32 +00:00
""" Calculates amount_tax of order line
@param field_names : Names of fields .
@return : Dictionary of values """
2008-08-24 14:45:43 +00:00
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 )
2009-11-24 12:31:07 +00:00
WHERE p . id = ANY ( % s ) GROUP BY p . id """ ,(ids,))
2008-08-24 14:45:43 +00:00
res = dict ( cr . fetchall ( ) )
for rec in self . browse ( cr , uid , ids , context ) :
2008-12-17 09:37:31 +00:00
if rec . partner_id \
and rec . partner_id . property_account_position \
and rec . partner_id . property_account_position . tax_ids :
2008-08-24 14:45:43 +00:00
res [ rec . id ] = res [ rec . id ] - rec . amount_tax
2010-01-18 08:38:26 +00:00
else :
res [ rec . id ] = res [ rec . id ] + rec . amount_tax
2008-08-24 14:45:43 +00:00
return res
2010-01-18 08:38:26 +00:00
def _get_date_payment2 ( self , cr , uid , ids , context , * a ) :
2010-04-08 09:20:32 +00:00
# Todo need to check this function
""" Find payment Date
@param field_names : Names of fields .
@return : Dictionary of values """
2010-01-18 08:38:26 +00:00
res = { }
pay_obj = self . pool . get ( ' account.bank.statement ' )
stat_obj_line = self . pool . get ( ' account.bank.statement.line ' )
tot = 0.0
val = None
for order in self . browse ( cr , uid , ids ) :
2010-04-26 10:30:38 +00:00
cr . execute ( " select date_payment from pos_order where id= %d " % ( order . id ) )
date_p = cr . fetchone ( )
date_p = date_p and date_p [ 0 ] or None
if date_p :
res [ order . id ] = date_p
2010-01-18 08:38:26 +00:00
return res
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= %d and o.invoice_id=i.id " % ( order . id ) )
val = cr . fetchone ( )
val = val and val [ 0 ] or None
if not val :
cr . execute ( " select max(date) from account_bank_statement_line l, account_bank_statement_reconcile s where l.pos_statement_id= %d and l.reconcile_id=s.id " % ( order . id ) )
val = cr . fetchone ( )
val = val and val [ 0 ] or None
if val :
res [ order . id ] = val
return res
2010-04-08 09:20:32 +00:00
2010-01-18 08:38:26 +00:00
def _get_date_payment ( self , cr , uid , ids , context , * a ) :
2010-04-08 09:20:32 +00:00
""" Find Validation Date
@return : Dictionary of values """
2010-01-18 08:38:26 +00:00
res = { }
pay_obj = self . pool . get ( ' pos.payment ' )
tot = 0.0
val = None
for order in self . browse ( cr , uid , ids ) :
2010-04-26 10:30:38 +00:00
cr . execute ( " select date_validation from pos_order where id= %d " % ( order . id ) )
date_p = cr . fetchone ( )
date_p = date_p and date_p [ 0 ] or None
if date_p :
res [ order . id ] = date_p
2010-01-18 08:38:26 +00:00
return res
discount_allowed = order . company_id . company_discount
for line in order . lines :
if line . discount > discount_allowed :
return { order . id : None }
2010-04-26 10:30:38 +00:00
if order . amount_paid == order . amount_total and not date_p :
2010-01-18 08:38:26 +00:00
cr . execute ( " select max(date) from account_bank_statement_line where pos_statement_id= %d " % ( order . id ) )
val = cr . fetchone ( )
val = val and val [ 0 ] or None
2010-04-26 10:30:38 +00:00
if order . invoice_id and order . invoice_id . move_id and not date_p and not val :
2010-01-18 08:38:26 +00:00
for o in order . invoice_id . move_id . line_id :
if o . balance == 0 :
if val < o . date_created :
val = o . date_created
if val :
res [ order . id ] = val
return res
2010-04-26 10:30:38 +00:00
def _amount_all ( self , cr , uid , ids , name , args , context = None ) :
tax_obj = self . pool . get ( ' account.tax ' )
res = { }
2008-08-24 14:45:43 +00:00
for order in self . browse ( cr , uid , ids ) :
2010-04-26 10:30:38 +00:00
res [ order . id ] = {
' amount_paid ' : 0.0 ,
' amount_return ' : 0.0 ,
' amount_tax ' : 0.0 ,
}
for payment in order . statement_ids :
res [ order . id ] [ ' amount_paid ' ] + = payment . amount
for payment in order . payments :
res [ order . id ] [ ' amount_return ' ] + = ( payment . amount < 0 and payment . amount or 0 )
2008-08-24 14:45:43 +00:00
for line in order . lines :
2010-01-18 08:38:26 +00:00
if order . price_type != ' tax_excluded ' :
2010-04-26 10:30:38 +00:00
res [ order . id ] [ ' amount_tax ' ] = reduce ( lambda x , y : x + round ( y [ ' amount ' ] , 2 ) ,
2008-08-24 14:45:43 +00:00
tax_obj . compute_inv ( cr , uid , line . product_id . taxes_id ,
line . price_unit * \
( 1 - ( line . discount or 0.0 ) / 100.0 ) , line . qty ) ,
2010-04-26 10:30:38 +00:00
res [ order . id ] [ ' amount_tax ' ] )
2010-01-18 08:38:26 +00:00
else :
2010-04-26 10:30:38 +00:00
res [ order . id ] [ ' amount_tax ' ] = reduce ( lambda x , y : x + round ( y [ ' amount ' ] , 2 ) ,
2010-01-18 08:38:26 +00:00
tax_obj . compute ( cr , uid , line . product_id . taxes_id ,
line . price_unit * \
( 1 - ( line . discount or 0.0 ) / 100.0 ) , line . qty ) ,
2010-04-26 10:30:38 +00:00
res [ order . id ] [ ' amount_tax ' ] )
2008-08-24 14:45:43 +00:00
return res
2010-04-08 09:20:32 +00:00
2008-08-24 14:45:43 +00:00
2010-04-26 10:30:38 +00:00
2008-08-24 14:45:43 +00:00
def _sale_journal_get ( self , cr , uid , context ) :
2010-04-08 09:20:32 +00:00
""" To get sale journal for this order "
@return : journal """
2008-08-24 14:45:43 +00:00
journal_obj = self . pool . get ( ' account.journal ' )
res = journal_obj . search ( cr , uid ,
[ ( ' type ' , ' = ' , ' sale ' ) ] , limit = 1 )
if res :
return res [ 0 ]
else :
return False
2010-01-18 08:38:26 +00:00
def _shop_get ( self , cr , uid , context ) :
2010-04-08 09:20:32 +00:00
""" To get Shop for this order "
@return : Shop id """
2010-01-18 08:38:26 +00:00
company = self . pool . get ( ' res.users ' ) . browse ( cr , uid , uid , context ) . company_id
res = self . pool . get ( ' sale.shop ' ) . search ( cr , uid , [ ] )
if res :
return res [ 0 ]
else :
return False
2008-08-24 14:45:43 +00:00
def copy ( self , cr , uid , id , default = None , context = { } ) :
2010-04-08 09:20:32 +00:00
2008-08-24 14:45:43 +00:00
if not default :
default = { }
default . update ( {
' state ' : ' draft ' ,
' payments ' : [ ] ,
2009-07-03 11:24:12 +00:00
' partner_id ' : False ,
2008-08-24 14:45:43 +00:00
' invoice_id ' : False ,
' account_move ' : False ,
2010-05-13 08:21:42 +00:00
' picking_id ' : False ,
2008-08-24 14:45:43 +00:00
' nb_print ' : 0 ,
' pickings ' : [ ]
} )
return super ( pos_order , self ) . copy ( cr , uid , id , default , context )
2010-01-18 08:38:26 +00:00
def _get_v ( self , cr , uid , ids , * a ) :
2010-04-08 09:20:32 +00:00
""" Changed the Validation state of order
@return : State """
2010-01-18 08:38:26 +00:00
flag = False
res_company = self . pool . get ( ' res.company ' )
res_obj = self . pool . get ( ' res.users ' )
company_disc = self . browse ( cr , uid , ids )
if not company_disc :
comp = res_obj . browse ( cr , uid , uid ) . company_id . company_discount or 0.0
else :
comp = company_disc [ 0 ] and company_disc [ 0 ] . company_id and company_disc [ 0 ] . company_id . company_discount or 0.0
2010-04-26 10:30:38 +00:00
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 ( )
2010-01-18 08:38:26 +00:00
list_jrnl = [ ]
for r in res3 :
2010-04-26 10:30:38 +00:00
cr . execute ( " select id from account_journal where name= ' %s ' and special_journal= ' t ' " % ( r [ 0 ] ) )
res3 = cr . fetchone ( )
2010-01-18 08:38:26 +00:00
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 ) :
r [ order . id ] = ' accepted '
return r
2008-08-24 14:45:43 +00:00
_columns = {
' name ' : fields . char ( ' Order Description ' , size = 64 , required = True ,
states = { ' draft ' : [ ( ' readonly ' , False ) ] } , readonly = True ) ,
2010-01-18 08:38:26 +00:00
' company_id ' : fields . many2one ( ' res.company ' , ' Company ' , required = True , readonly = True ) ,
' num_sale ' : fields . char ( ' Internal Note ' , size = 64 ) ,
2008-08-24 14:45:43 +00:00
' shop_id ' : fields . many2one ( ' sale.shop ' , ' Shop ' , required = True ,
states = { ' draft ' : [ ( ' readonly ' , False ) ] } , readonly = True ) ,
2009-06-17 13:32:24 +00:00
' date_order ' : fields . datetime ( ' Date Ordered ' , readonly = True ) ,
2010-04-20 13:50:58 +00:00
' 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 ) ,
2008-08-24 14:45:43 +00:00
' date_validity ' : fields . date ( ' Validity Date ' , required = True ) ,
2010-01-18 08:38:26 +00:00
' user_id ' : fields . many2one ( ' res.users ' , ' Connected Salesman ' , readonly = True ) ,
2010-05-05 09:58:24 +00:00
' user_salesman_id ' : fields . many2one ( ' res.users ' , ' Salesman ' , required = True ) ,
2010-04-20 13:50:58 +00:00
' sale_manager ' : fields . many2one ( ' res.users ' , ' Salesman Manager ' ) ,
2010-04-26 10:30:38 +00:00
' amount_tax ' : fields . function ( _amount_all , method = True , string = ' Taxes ' , digits_compute = dp . get_precision ( ' Point Of Sale ' ) , multi = ' all ' ) ,
2009-06-17 13:32:24 +00:00
' amount_total ' : fields . function ( _amount_total , method = True , string = ' Total ' ) ,
2010-04-26 10:30:38 +00:00
' amount_paid ' : fields . function ( _amount_all , ' Paid ' , states = { ' draft ' : [ ( ' readonly ' , False ) ] } , readonly = True , method = True , digits_compute = dp . get_precision ( ' Point Of Sale ' ) , multi = ' all ' ) ,
' amount_return ' : fields . function ( _amount_all , ' Returned ' , method = True , digits_compute = dp . get_precision ( ' Point Of Sale ' ) , multi = ' all ' ) ,
2010-01-18 08:38:26 +00:00
' 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 ' ) ,
' payments ' : fields . one2many ( ' pos.payment ' , ' order_id ' , ' Order 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 ' , ' Draft ' ) , ( ' payment ' , ' Payment ' ) ,
( ' advance ' , ' Advance ' ) ,
( ' paid ' , ' Paid ' ) , ( ' done ' , ' Done ' ) , ( ' invoiced ' , ' Invoiced ' ) , ( ' cancel ' , ' Cancel ' ) ] ,
' State ' , readonly = True , ) ,
' invoice_id ' : fields . many2one ( ' account.invoice ' , ' Invoice ' ) ,
2009-06-17 13:32:24 +00:00
' account_move ' : fields . many2one ( ' account.move ' , ' Account Entry ' , readonly = True ) ,
' pickings ' : fields . one2many ( ' stock.picking ' , ' pos_order ' , ' Picking ' , readonly = True ) ,
2010-05-13 08:21:42 +00:00
' picking_id ' : fields . many2one ( ' stock.picking ' , ' Last Output Picking ' , readonly = True ) ,
2010-01-18 08:38:26 +00:00
' first_name ' : fields . char ( ' First Name ' , size = 64 ) ,
' state_2 ' : fields . function ( _get_v , type = ' selection ' , selection = [ ( ' to_verify ' , ' To Verify ' ) , ( ' accepted ' , ' Accepted ' ) ,
( ' refused ' , ' Refused ' ) ] , string = ' State ' , readonly = True , method = True , store = True ) ,
' note ' : fields . text ( ' Internal Notes ' ) ,
2009-01-27 11:15:46 +00:00
' nb_print ' : fields . integer ( ' Number of Print ' , readonly = True ) ,
2010-01-18 08:38:26 +00:00
' 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 ) ,
' remboursed ' : fields . boolean ( ' Remboursed ' ) ,
2010-04-23 14:57:42 +00:00
' contract_number ' : fields . char ( ' Contract Number ' , size = 512 , select = 1 ) ,
2010-01-18 08:38:26 +00:00
' journal_entry ' : fields . boolean ( ' Journal Entry ' ) ,
}
def _select_pricelist ( self , cr , uid , context ) :
2010-04-08 09:20:32 +00:00
""" To get default pricelist for the order "
@param name : Names of fields .
@return : pricelist ID
"""
2010-01-18 08:38:26 +00:00
pricelist = self . pool . get ( ' product.pricelist ' ) . search ( cr , uid , [ ( ' name ' , ' = ' , ' Public Pricelist ' ) ] )
if pricelist :
return pricelist [ 0 ]
else :
return False
2008-08-24 14:45:43 +00:00
def _journal_default ( self , cr , uid , context = { } ) :
2010-04-08 09:20:32 +00:00
""" To get default pricelist for the order "
@param name : Names of fields .
@return : journal ID
"""
2008-08-24 14:45:43 +00:00
journal_list = self . pool . get ( ' account.journal ' ) . search ( cr , uid , [ ( ' type ' , ' = ' , ' cash ' ) ] )
if journal_list :
return journal_list [ 0 ]
else :
return False
_defaults = {
2010-05-17 08:44:20 +00:00
' user_salesman_id ' : lambda self , cr , uid , context : uid ,
2008-08-24 14:45:43 +00:00
' user_id ' : lambda self , cr , uid , context : uid ,
2010-04-20 13:50:58 +00:00
' sale_manager ' : lambda self , cr , uid , context : uid ,
2008-08-24 14:45:43 +00:00
' state ' : lambda * a : ' draft ' ,
2010-01-18 08:38:26 +00:00
' price_type ' : lambda * a : ' tax_excluded ' ,
' state_2 ' : lambda * a : ' to_verify ' ,
' name ' : lambda obj , cr , uid , context : obj . pool . get ( ' ir.sequence ' ) . get ( cr , uid , ' pos.order ' ) ,
2009-06-17 13:32:24 +00:00
' date_order ' : lambda * a : time . strftime ( ' % Y- % m- %d % H: % M: % S ' ) ,
2008-08-24 14:45:43 +00:00
' date_validity ' : lambda * a : ( DateTime . now ( ) + DateTime . RelativeDateTime ( months = + 6 ) ) . strftime ( ' % Y- % m- %d ' ) ,
' nb_print ' : lambda * a : 0 ,
2010-01-18 08:38:26 +00:00
' company_id ' : lambda self , cr , uid , c : self . pool . get ( ' res.users ' ) . browse ( cr , uid , uid , c ) . company_id . id ,
2008-08-24 14:45:43 +00:00
' sale_journal ' : _sale_journal_get ,
2010-01-18 08:38:26 +00:00
' invoice_wanted ' : lambda * a : False ,
' shop_id ' : _shop_get ,
' pricelist_id ' : _select_pricelist ,
2008-08-24 14:45:43 +00:00
}
2010-01-18 08:38:26 +00:00
2008-08-24 14:45:43 +00:00
def test_order_lines ( self , cr , uid , order , context = { } ) :
2010-04-08 09:20:32 +00:00
""" Test order line is created or not for the order "
@param name : Names of fields .
@return : True
"""
2008-08-24 14:45:43 +00:00
if not order . lines :
2009-03-06 22:18:24 +00:00
raise osv . except_osv ( _ ( ' Error ' ) , _ ( ' No order lines defined for this sale. ' ) )
2008-08-24 14:45:43 +00:00
wf_service = netsvc . LocalService ( " workflow " )
wf_service . trg_validate ( uid , ' pos.order ' , order . id , ' paid ' , cr )
return True
def dummy_button ( self , cr , uid , order , context = { } ) :
return True
def test_paid ( self , cr , uid , ids , context = None ) :
2010-04-08 09:20:32 +00:00
""" Test all amount is paid for this order
@return : True
"""
2008-08-24 14:45:43 +00:00
for order in self . browse ( cr , uid , ids , context ) :
if order . lines and not order . amount_total :
return True
2010-01-18 08:38:26 +00:00
if ( not order . lines ) or ( not order . statement_ids ) or \
Decimal ( str ( order . amount_total ) ) != Decimal ( str ( order . amount_paid ) ) :
2008-08-24 14:45:43 +00:00
return False
return True
def _get_qty_differences ( self , orders , old_picking ) :
2010-04-08 09:20:32 +00:00
""" check if the customer changed the product quantity """
2008-08-24 14:45:43 +00:00
order_dict = { }
for order in orders :
for line in order . lines :
order_dict [ line . product_id . id ] = line
# check the quantity differences:
diff_dict = { }
for line in old_picking . move_lines :
order_line = order_dict . get ( line . product_id . id )
if not order_line :
deleted = True
qty_to_delete_from_original_picking = line . product_qty
diff_dict [ line . product_id . id ] = ( deleted , qty_to_delete_from_original_picking )
elif line . product_qty != order_line . qty :
deleted = False
qty_to_delete_from_original_picking = line . product_qty - order_line . qty
diff_dict [ line . product_id . id ] = ( deleted , qty_to_delete_from_original_picking )
return diff_dict
def _split_picking ( self , cr , uid , ids , context , old_picking , diff_dict ) :
2010-04-08 09:20:32 +00:00
2008-08-24 14:45:43 +00:00
""" if the customer changes the product quantity, split the picking in two """
2010-04-08 09:20:32 +00:00
2008-08-24 14:45:43 +00:00
# create a copy of the original picking and adjust the product qty:
picking_model = self . pool . get ( ' stock.picking ' )
defaults = {
' note ' : " Partial picking from customer " , # add a note to tell why we create a new picking
' name ' : self . pool . get ( ' ir.sequence ' ) . get ( cr , uid , ' stock.picking.out ' ) , # increment the sequence
}
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 )
for line in new_picking . move_lines :
p_id = line . product_id . id
if p_id in diff_dict :
diff = diff_dict [ p_id ]
deleted = diff [ 0 ]
qty_to_del = diff [ 1 ]
if deleted : # product has been deleted (customer didn't took it):
# delete this product from old picking:
for old_line in old_picking . move_lines :
if old_line . product_id . id == p_id :
2009-06-02 09:34:57 +00:00
old_line . write ( { ' state ' : ' draft ' } , context = context ) # cannot delete if not draft
old_line . unlink ( context = context )
2008-08-24 14:45:43 +00:00
elif qty_to_del > 0 : # product qty has been modified (customer took less than the ordered quantity):
# subtract qty from old picking:
for old_line in old_picking . move_lines :
if old_line . product_id . id == p_id :
2009-06-02 09:34:57 +00:00
old_line . write ( { ' product_qty ' : old_line . product_qty - qty_to_del } , context = context )
2008-08-24 14:45:43 +00:00
# add qty to new picking:
2009-06-02 09:34:57 +00:00
line . write ( { ' product_qty ' : qty_to_del } , context = context )
2008-08-24 14:45:43 +00:00
else : # product hasn't changed (customer took it without any change):
# delete this product from new picking:
2009-06-02 09:34:57 +00:00
line . unlink ( context = context )
2008-08-24 14:45:43 +00:00
else :
# delete it in the new picking:
2009-06-02 09:34:57 +00:00
line . unlink ( context = context )
2008-08-24 14:45:43 +00:00
def create_picking ( self , cr , uid , ids , context = { } ) :
2010-04-08 09:20:32 +00:00
2008-08-24 14:45:43 +00:00
""" Create a picking for each order and validate it. """
2010-04-08 09:20:32 +00:00
2008-08-24 14:45:43 +00:00
picking_obj = self . pool . get ( ' stock.picking ' )
2010-05-24 07:16:41 +00:00
pick_name = self . pool . get ( ' ir.sequence ' ) . get ( cr , uid , ' stock.picking.out ' )
2008-08-24 14:45:43 +00:00
orders = self . browse ( cr , uid , ids , context )
for order in orders :
2010-05-13 08:21:42 +00:00
if not order . picking_id :
2008-08-24 14:45:43 +00:00
new = True
picking_id = picking_obj . create ( cr , uid , {
2010-05-24 07:16:41 +00:00
' name ' : pick_name ,
2008-08-24 14:45:43 +00:00
' origin ' : order . name ,
' type ' : ' out ' ,
' state ' : ' draft ' ,
' move_type ' : ' direct ' ,
' note ' : ' POS notes ' + ( order . note or " " ) ,
' invoice_state ' : ' none ' ,
' auto_picking ' : True ,
' pos_order ' : order . id ,
2010-01-18 08:38:26 +00:00
} )
2010-05-13 08:21:42 +00:00
self . write ( cr , uid , [ order . id ] , { ' picking_id ' : picking_id } )
2008-08-24 14:45:43 +00:00
else :
2010-05-13 08:21:42 +00:00
picking_id = order . picking_id . id
2010-01-18 08:38:26 +00:00
picking_obj . write ( cr , uid , [ picking_id ] , { ' auto_picking ' : True } )
2008-08-24 14:45:43 +00:00
picking = picking_obj . browse ( cr , uid , [ picking_id ] , context ) [ 0 ]
new = False
# split the picking (if product quantity has changed):
diff_dict = self . _get_qty_differences ( orders , picking )
if diff_dict :
self . _split_picking ( cr , uid , ids , context , picking , diff_dict )
if new :
for line in order . lines :
2010-01-18 08:38:26 +00:00
if line . product_id and line . product_id . type == ' service ' :
continue
prop_ids = self . pool . get ( " ir.property " ) . search ( cr , uid , [ ( ' name ' , ' = ' , ' property_stock_customer ' ) ] )
2010-05-06 07:20:19 +00:00
val = self . pool . get ( " ir.property " ) . browse ( cr , uid , prop_ids [ 0 ] ) . value_reference
2010-01-18 08:38:26 +00:00
cr . execute ( " select s.id from stock_location s, stock_warehouse w where w.lot_stock_id=s.id and w.id= %d " % ( order . shop_id . warehouse_id . id ) )
res = cr . fetchone ( )
location_id = res and res [ 0 ] or None
2010-04-23 14:57:42 +00:00
# location_id = order and order.shop_id and order.shop_id.warehouse_id and order.shop_id.warehouse_id.lot_stock_id.id or None
2010-05-06 07:20:19 +00:00
stock_dest_id = val . id
2008-08-24 14:45:43 +00:00
if line . qty < 0 :
2010-01-18 08:38:26 +00:00
location_id , stock_dest_id = stock_dest_id , location_id
2008-08-24 14:45:43 +00:00
2010-05-24 07:47:07 +00:00
self . pool . get ( ' stock.move ' ) . create ( cr , uid , {
2009-12-07 15:08:52 +00:00
' name ' : ' Stock move (POS %d ) ' % ( order . id , ) ,
' product_uom ' : line . product_id . uom_id . id ,
' product_uos ' : line . product_id . uom_id . id ,
' picking_id ' : picking_id ,
' product_id ' : line . product_id . id ,
' product_uos_qty ' : abs ( line . qty ) ,
' product_qty ' : abs ( line . qty ) ,
' tracking_id ' : False ,
2010-01-21 15:13:50 +00:00
' pos_line_id ' : line . id ,
2009-12-07 15:08:52 +00:00
' state ' : ' waiting ' ,
' location_id ' : location_id ,
' location_dest_id ' : stock_dest_id ,
} )
2008-08-24 14:45:43 +00:00
2008-12-20 09:43:37 +00:00
wf_service = netsvc . LocalService ( " workflow " )
2010-01-18 08:38:26 +00:00
wf_service . trg_validate ( uid , ' stock.picking ' , picking_id , ' button_confirm ' , cr )
self . pool . get ( ' stock.picking ' ) . force_assign ( cr , uid , [ picking_id ] , context )
2008-08-24 14:45:43 +00:00
return True
def set_to_draft ( self , cr , uid , ids , * args ) :
2010-04-08 09:20:32 +00:00
""" Changes order state to draft
@return : True
"""
2008-08-24 14:45:43 +00:00
if not len ( ids ) :
return False
self . write ( cr , uid , ids , { ' state ' : ' draft ' } )
wf_service = netsvc . LocalService ( " workflow " )
for i in ids :
wf_service . trg_create ( uid , ' pos.order ' , i , cr )
return True
2010-01-18 08:38:26 +00:00
def button_invalidate ( self , cr , uid , ids , * args ) :
2010-04-08 09:20:32 +00:00
""" Check the access for the sale order
@return : True
"""
2010-01-18 08:38:26 +00:00
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
except Exception , e :
raise osv . except_osv ( _ ( ' Error ' ) , _ ( ' You don \' t have enough access to validate this sale! ' ) )
if part_company :
raise osv . except_osv ( _ ( ' Error ' ) , _ ( ' You don \' t have enough access to validate this sale! ' ) )
return True
2008-08-24 14:45:43 +00:00
2010-01-18 08:38:26 +00:00
def button_validate ( self , cr , uid , ids , * args ) :
2010-04-08 09:20:32 +00:00
2010-04-20 13:50:58 +00:00
""" Check the access for the sale order and update the date_validation
2010-04-08 09:20:32 +00:00
@return : True
"""
2010-01-18 08:38:26 +00:00
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
except Exception , e :
raise osv . except_osv ( _ ( ' Error ' ) , _ ( ' You don \' t have enough access to validate this sale! ' ) )
if part_company :
raise osv . except_osv ( _ ( ' Error ' ) , _ ( ' You don \' t have enough access to validate this sale! ' ) )
for order in self . browse ( cr , uid , ids ) :
2010-04-20 13:50:58 +00:00
if not order . date_validation :
2010-01-18 08:38:26 +00:00
cr . execute ( " select max(date) from account_bank_statement_line where pos_statement_id= %d " % ( order . id ) )
val = cr . fetchone ( )
val = val and val [ 0 ] or None
if val :
2010-04-20 13:50:58 +00:00
cr . execute ( " Update pos_order set date_validation= ' %s ' where id = %d " % ( val , order . id ) )
2010-01-18 08:38:26 +00:00
return True
2008-08-24 14:45:43 +00:00
2010-01-18 08:38:26 +00:00
def cancel_order ( self , cr , uid , ids , context = None ) :
2010-04-08 09:20:32 +00:00
""" Changes order state to cancel
@return : True
"""
2010-01-18 08:38:26 +00:00
self . write ( cr , uid , ids , { ' state ' : ' cancel ' } )
self . cancel_picking ( cr , uid , ids , context = { } )
2008-08-24 14:45:43 +00:00
return True
2008-12-20 18:29:38 +00:00
def add_payment ( self , cr , uid , order_id , data , context = None ) :
2010-04-08 09:20:32 +00:00
2008-08-24 14:45:43 +00:00
""" Create a new payment for the order """
2010-04-08 09:20:32 +00:00
2010-01-18 08:38:26 +00:00
res_obj = self . pool . get ( ' res.company ' )
statementl_obj = self . pool . get ( ' account.bank.statement.line ' )
prod_obj = self . pool . get ( ' product.product ' )
flag = ' '
curr_c = self . pool . get ( ' res.users ' ) . browse ( cr , uid , uid ) . company_id
curr_company = curr_c . id
2008-08-24 14:45:43 +00:00
order = self . browse ( cr , uid , order_id , context )
2010-01-18 08:38:26 +00:00
if not order . num_sale and data [ ' num_sale ' ] :
self . write ( cr , uid , order_id , { ' num_sale ' : data [ ' num_sale ' ] } )
ids_new = [ ]
2008-08-24 14:45:43 +00:00
if order . invoice_wanted and not order . partner_id :
2009-03-06 22:18:24 +00:00
raise osv . except_osv ( _ ( ' Error ' ) , _ ( ' Cannot create invoice without a partner. ' ) )
2008-12-20 18:29:38 +00:00
args = {
' amount ' : data [ ' amount ' ] ,
}
if ' payment_date ' in data . keys ( ) :
2010-01-18 08:38:26 +00:00
args [ ' date ' ] = data [ ' payment_date ' ]
2008-12-20 18:29:38 +00:00
if ' payment_name ' in data . keys ( ) :
2010-01-18 08:38:26 +00:00
args [ ' name ' ] = data [ ' payment_name ' ] + ' ' + order . name
account_def = self . pool . get ( ' ir.property ' ) . get ( cr , uid , ' property_account_receivable ' , ' res.partner ' , context = context )
2010-05-06 10:11:38 +00:00
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
2010-01-18 08:38:26 +00:00
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
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 ) )
args [ ' partner_id ' ] = order . partner_id and order . partner_id . id or None
args [ ' ref ' ] = order . contract_number or None
statement_obj = self . pool . get ( ' account.bank.statement ' )
statement_id = statement_obj . search ( cr , uid , [
( ' journal_id ' , ' = ' , data [ ' journal ' ] ) ,
( ' company_id ' , ' = ' , curr_company ) ,
( ' user_id ' , ' = ' , uid ) ,
( ' state ' , ' = ' , ' open ' ) ] )
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 ' ]
2010-04-08 09:20:32 +00:00
statement_line_id = statementl_obj . create ( cr , uid , args )
2010-01-18 08:38:26 +00:00
ids_new . append ( statement_id )
2008-08-24 14:45:43 +00:00
2008-12-20 09:43:37 +00:00
wf_service = netsvc . LocalService ( " workflow " )
2009-05-11 11:44:26 +00:00
wf_service . trg_validate ( uid , ' pos.order ' , order_id , ' paid ' , cr )
2008-12-20 09:43:37 +00:00
wf_service . trg_write ( uid , ' pos.order ' , order_id , cr )
2010-01-18 08:38:26 +00:00
return statement_id
2008-08-24 14:45:43 +00:00
def add_product ( self , cr , uid , order_id , product_id , qty , context = None ) :
2010-04-08 09:20:32 +00:00
2008-08-24 14:45:43 +00:00
""" Create a new order line the order """
2010-04-08 09:20:32 +00:00
2008-08-24 14:45:43 +00:00
line_obj = self . pool . get ( ' pos.order.line ' )
values = self . read ( cr , uid , order_id , [ ' partner_id ' , ' pricelist_id ' ] )
pricelist = values [ ' pricelist_id ' ] and values [ ' pricelist_id ' ] [ 0 ]
product = values [ ' partner_id ' ] and values [ ' partner_id ' ] [ 0 ]
price = line_obj . price_by_product ( cr , uid , [ ] ,
pricelist , product_id , qty , product )
order_line_id = line_obj . create ( cr , uid , {
' order_id ' : order_id ,
' product_id ' : product_id ,
' qty ' : qty ,
' price_unit ' : price ,
} )
2008-12-20 09:43:37 +00:00
wf_service = netsvc . LocalService ( " workflow " )
wf_service . trg_write ( uid , ' pos.order ' , order_id , cr )
2008-08-24 14:45:43 +00:00
return order_line_id
def refund ( self , cr , uid , ids , context = { } ) :
2010-04-08 09:20:32 +00:00
""" Create a copy of order for refund order """
2008-08-24 14:45:43 +00:00
clone_list = [ ]
line_obj = self . pool . get ( ' pos.order.line ' )
for order in self . browse ( cr , uid , ids ) :
clone_id = self . copy ( cr , uid , order . id , {
' name ' : order . name + ' REFUND ' ,
' date_order ' : time . strftime ( ' % Y- % m- %d ' ) ,
' state ' : ' draft ' ,
' note ' : ' REFUND \n ' + ( order . note or ' ' ) ,
' invoice_id ' : False ,
' nb_print ' : 0 ,
2010-01-18 08:38:26 +00:00
' statement_ids ' : False ,
2008-08-24 14:45:43 +00:00
} )
clone_list . append ( clone_id )
2010-01-18 08:38:26 +00:00
2008-08-24 14:45:43 +00:00
for clone in self . browse ( cr , uid , clone_list ) :
for order_line in clone . lines :
line_obj . write ( cr , uid , [ order_line . id ] , {
2010-01-18 08:38:26 +00:00
' qty ' : - order_line . qty
2008-08-24 14:45:43 +00:00
} )
return clone_list
def action_invoice ( self , cr , uid , ids , context = { } ) :
2010-04-08 09:20:32 +00:00
""" Create a invoice of order """
2010-01-18 08:38:26 +00:00
res_obj = self . pool . get ( ' res.company ' )
2008-08-24 14:45:43 +00:00
inv_ref = self . pool . get ( ' account.invoice ' )
inv_line_ref = self . pool . get ( ' account.invoice.line ' )
2010-04-08 09:20:32 +00:00
product_obj = self . pool . get ( ' product.product ' )
2008-08-24 14:45:43 +00:00
inv_ids = [ ]
for order in self . browse ( cr , uid , ids , context ) :
2010-05-05 09:58:24 +00:00
curr_c = order . user_salesman_id . company_id
2008-08-24 14:45:43 +00:00
if order . invoice_id :
inv_ids . append ( order . invoice_id . id )
continue
if not order . partner_id :
2009-03-06 22:18:24 +00:00
raise osv . except_osv ( _ ( ' Error ' ) , _ ( ' Please provide a partner for the sale. ' ) )
2008-08-24 14:45:43 +00:00
2010-04-24 05:09:53 +00:00
acc = order . partner_id . property_account_receivable . id
2008-08-24 14:45:43 +00:00
inv = {
' name ' : ' Invoice from POS: ' + order . name ,
' origin ' : order . name ,
2010-01-18 08:38:26 +00:00
' account_id ' : acc ,
' journal_id ' : order . sale_journal . id or None ,
2008-08-24 14:45:43 +00:00
' type ' : ' out_invoice ' ,
' reference ' : order . name ,
' partner_id ' : order . partner_id . id ,
' comment ' : order . note or ' ' ,
}
inv . update ( inv_ref . onchange_partner_id ( cr , uid , [ ] , ' out_invoice ' , order . partner_id . id ) [ ' value ' ] )
2010-01-18 08:38:26 +00:00
if not inv . get ( ' account_id ' , None ) :
inv [ ' account_id ' ] = acc
2008-08-24 14:45:43 +00:00
inv_id = inv_ref . create ( cr , uid , inv , context )
self . write ( cr , uid , [ order . id ] , { ' invoice_id ' : inv_id , ' state ' : ' invoiced ' } )
inv_ids . append ( inv_id )
for line in order . lines :
inv_line = {
' invoice_id ' : inv_id ,
' product_id ' : line . product_id . id ,
' quantity ' : line . qty ,
}
2010-04-08 09:20:32 +00:00
inv_name = product_obj . name_get ( cr , uid , [ line . product_id . id ] , context = context ) [ 0 ] [ 1 ]
2010-02-03 05:47:12 +00:00
2008-08-24 14:45:43 +00:00
inv_line . update ( inv_line_ref . product_id_change ( cr , uid , [ ] ,
2010-01-18 08:38:26 +00:00
line . product_id . id ,
line . product_id . uom_id . id ,
line . qty , partner_id = order . partner_id . id , fposition_id = order . partner_id . property_account_position . id ) [ ' value ' ] )
2008-08-24 14:45:43 +00:00
inv_line [ ' price_unit ' ] = line . price_unit
inv_line [ ' discount ' ] = line . discount
2010-01-18 08:38:26 +00:00
inv_line [ ' account_id ' ] = acc
2010-02-03 05:47:12 +00:00
inv_line [ ' name ' ] = inv_name
2008-08-24 14:45:43 +00:00
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 )
for i in inv_ids :
2008-12-20 09:43:37 +00:00
wf_service = netsvc . LocalService ( " workflow " )
wf_service . trg_validate ( uid , ' account.invoice ' , i , ' invoice_open ' , cr )
2008-08-24 14:45:43 +00:00
return inv_ids
def create_account_move ( self , cr , uid , ids , context = None ) :
2010-04-08 09:20:32 +00:00
""" Create a account move line of order """
2008-08-24 14:45:43 +00:00
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 ' )
account_tax_obj = self . pool . get ( ' account.tax ' )
2010-04-24 05:09:53 +00:00
res_obj = self . pool . get ( ' res.users ' )
property_obj = self . pool . get ( ' ir.property ' )
2008-08-24 14:45:43 +00:00
period = account_period_obj . find ( cr , uid , context = context ) [ 0 ]
for order in self . browse ( cr , uid , ids , context = context ) :
2010-04-24 05:09:53 +00:00
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
2010-01-18 08:38:26 +00:00
comp_id = comp_id and comp_id . id or False
2008-08-24 14:45:43 +00:00
to_reconcile = [ ]
group_tax = { }
2010-05-17 08:44:20 +00:00
account_def = property_obj . get ( cr , uid , ' property_account_receivable ' , ' res.partner ' , context = context ) . id
2010-01-18 08:38:26 +00:00
order_account = order . partner_id and order . partner_id . property_account_receivable and order . partner_id . property_account_receivable . id or account_def or curr_c . account_receivable . id
2008-08-24 14:45:43 +00:00
# Create an entry for the sale
move_id = account_move_obj . create ( cr , uid , {
' journal_id ' : order . sale_journal . id ,
' period_id ' : period ,
} , context = context )
# 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 ]
2010-01-18 08:38:26 +00:00
if order . price_type == ' tax_excluded ' :
computed_taxes = account_tax_obj . compute (
cr , uid , taxes , line . price_unit , line . qty )
else :
computed_taxes = account_tax_obj . compute_inv (
cr , uid , taxes , line . price_unit , line . qty )
2008-08-24 14:45:43 +00:00
for tax in computed_taxes :
tax_amount + = round ( tax [ ' amount ' ] , 2 )
group_key = ( tax [ ' tax_code_id ' ] ,
tax [ ' base_code_id ' ] ,
tax [ ' account_collected_id ' ] )
if group_key in group_tax :
group_tax [ group_key ] + = round ( tax [ ' amount ' ] , 2 )
else :
group_tax [ group_key ] = round ( tax [ ' amount ' ] , 2 )
2010-01-18 08:38:26 +00:00
if order . price_type != ' tax_excluded ' :
amount = line . price_subtotal - tax_amount
else :
amount = line . price_subtotal
2008-08-24 14:45:43 +00:00
# Search for the income account
if line . product_id . property_account_income . id :
income_account = line . \
product_id . property_account_income . id
elif line . product_id . categ_id . \
property_account_income_categ . id :
income_account = line . product_id . categ_id . \
property_account_income_categ . id
else :
2009-03-06 22:18:24 +00:00
raise osv . except_osv ( _ ( ' Error ! ' ) , _ ( ' There is no income ' \
' account defined for this product: " %s " (id: %d ) ' ) \
2008-08-24 14:45:43 +00:00
% ( 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
while computed_taxes :
tax = computed_taxes . pop ( 0 )
if amount > 0 :
tax_code_id = tax [ ' base_code_id ' ]
tax_amount = line . price_subtotal * tax [ ' base_sign ' ]
else :
tax_code_id = tax [ ' ref_base_code_id ' ]
tax_amount = line . price_subtotal * tax [ ' ref_base_sign ' ]
# If there is one we stop
if tax_code_id :
break
# Create a move for the line
account_move_line_obj . create ( cr , uid , {
2010-01-18 08:38:26 +00:00
' name ' : " aa " + order . name ,
2008-08-24 14:45:43 +00:00
' date ' : order . date_order ,
2010-01-18 08:38:26 +00:00
' ref ' : order . contract_number or order . name ,
' quantity ' : line . qty ,
' product_id ' : line . product_id . id ,
2008-08-24 14:45:43 +00:00
' move_id ' : move_id ,
' account_id ' : income_account ,
2010-01-18 08:38:26 +00:00
' company_id ' : comp_id ,
2008-08-24 14:45:43 +00:00
' credit ' : ( ( amount > 0 ) and amount ) or 0.0 ,
' debit ' : ( ( amount < 0 ) and - amount ) or 0.0 ,
' journal_id ' : order . sale_journal . id ,
' period_id ' : period ,
' tax_code_id ' : tax_code_id ,
' tax_amount ' : tax_amount ,
} , context = context )
# For each remaining tax with a code, whe create a move line
for tax in computed_taxes :
if amount > 0 :
tax_code_id = tax [ ' base_code_id ' ]
tax_amount = line . price_subtotal * tax [ ' base_sign ' ]
else :
tax_code_id = tax [ ' ref_base_code_id ' ]
tax_amount = line . price_subtotal * tax [ ' ref_base_sign ' ]
if not tax_code_id :
continue
account_move_line_obj . create ( cr , uid , {
2010-01-18 08:38:26 +00:00
' name ' : " bb " + order . name ,
2008-08-24 14:45:43 +00:00
' date ' : order . date_order ,
2010-01-18 08:38:26 +00:00
' ref ' : order . contract_number or order . name ,
' product_id ' : line . product_id . id ,
' quantity ' : line . qty ,
2008-08-24 14:45:43 +00:00
' move_id ' : move_id ,
' account_id ' : income_account ,
2010-01-18 08:38:26 +00:00
' company_id ' : comp_id ,
2008-08-24 14:45:43 +00:00
' credit ' : 0.0 ,
' debit ' : 0.0 ,
' journal_id ' : order . sale_journal . id ,
' period_id ' : period ,
' tax_code_id ' : tax_code_id ,
' tax_amount ' : tax_amount ,
} , context = context )
# Create a move for each tax group
( 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 , {
2010-01-18 08:38:26 +00:00
' name ' : " cc " + order . name ,
2008-08-24 14:45:43 +00:00
' date ' : order . date_order ,
2010-01-18 08:38:26 +00:00
' ref ' : order . contract_number or order . name ,
2008-08-24 14:45:43 +00:00
' move_id ' : move_id ,
2010-01-18 08:38:26 +00:00
' company_id ' : comp_id ,
' quantity ' : line . qty ,
' product_id ' : line . product_id . id ,
2008-08-24 14:45:43 +00:00
' account_id ' : key [ account_pos ] ,
' credit ' : ( ( amount > 0 ) and amount ) or 0.0 ,
' debit ' : ( ( amount < 0 ) and - amount ) or 0.0 ,
' journal_id ' : order . sale_journal . id ,
' period_id ' : period ,
' tax_code_id ' : key [ tax_code_pos ] ,
' tax_amount ' : amount ,
} , context = context )
# counterpart
to_reconcile . append ( account_move_line_obj . create ( cr , uid , {
2010-01-18 08:38:26 +00:00
' name ' : " dd " + order . name ,
2008-08-24 14:45:43 +00:00
' date ' : order . date_order ,
2010-01-18 08:38:26 +00:00
' ref ' : order . contract_number or order . name ,
2008-08-24 14:45:43 +00:00
' move_id ' : move_id ,
2010-01-18 08:38:26 +00:00
' company_id ' : comp_id ,
2008-08-24 14:45:43 +00:00
' account_id ' : order_account ,
' credit ' : ( ( order . amount_total < 0 ) and - order . amount_total ) \
or 0.0 ,
' debit ' : ( ( order . amount_total > 0 ) and order . amount_total ) \
or 0.0 ,
' journal_id ' : order . sale_journal . id ,
' period_id ' : period ,
} , context = context ) )
# search the account receivable for the payments:
account_receivable = order . sale_journal . default_credit_account_id . id
if not account_receivable :
2009-03-06 22:18:24 +00:00
raise osv . except_osv ( _ ( ' Error ! ' ) ,
_ ( ' There is no receivable account defined for this journal: ' \
' " %s " (id: %d ) ' ) % ( order . sale_journal . name , order . sale_journal . id , ) )
2010-01-18 08:38:26 +00:00
am = 0.0
for payment in order . statement_ids :
am + = payment . amount
2008-08-24 14:45:43 +00:00
2010-01-18 08:38:26 +00:00
if am > 0 :
payment_account = \
payment . statement_id . journal_id . default_debit_account_id . id
2008-08-24 14:45:43 +00:00
else :
2010-01-18 08:38:26 +00:00
payment_account = \
payment . statement_id . journal_id . default_credit_account_id . id
2008-08-24 14:45:43 +00:00
# Create one entry for the payment
2010-01-18 08:38:26 +00:00
if payment . is_acc :
continue
2008-08-24 14:45:43 +00:00
payment_move_id = account_move_obj . create ( cr , uid , {
2010-01-18 08:38:26 +00:00
' journal_id ' : payment . statement_id . journal_id . id ,
2008-08-24 14:45:43 +00:00
' period_id ' : period ,
} , context = context )
2010-01-18 08:38:26 +00:00
for stat_l in order . statement_ids :
if stat_l . is_acc and len ( stat_l . move_ids ) :
for st in stat_l . move_ids :
for s in st . line_id :
if s . credit :
account_move_line_obj . copy ( cr , uid , s . id , { ' debit ' : s . credit ,
' statement_id ' : False ,
' credit ' : s . debit } )
account_move_line_obj . copy ( cr , uid , s . id , {
' statement_id ' : False ,
' account_id ' : order_account
} )
2010-04-24 05:09:53 +00:00
2010-01-18 08:38:26 +00:00
self . write ( cr , uid , order . id , { ' state ' : ' done ' } )
return True
def cancel_picking ( self , cr , uid , ids , context = None ) :
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 )
2008-08-24 14:45:43 +00:00
return True
2010-01-18 08:38:26 +00:00
def action_payment ( self , cr , uid , ids , context = None ) :
vals = { ' state ' : ' payment ' }
2010-04-24 05:09:53 +00:00
sequence_obj = self . pool . get ( ' ir.sequence ' )
2010-01-18 08:38:26 +00:00
for pos in self . browse ( cr , uid , ids ) :
create_contract_nb = False
for line in pos . lines :
if line . product_id . product_type == ' MD ' :
create_contract_nb = True
break
if create_contract_nb :
2010-05-05 09:58:24 +00:00
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 )
2010-01-18 08:38:26 +00:00
self . write ( cr , uid , ids , vals )
2008-08-24 14:45:43 +00:00
def action_paid ( self , cr , uid , ids , context = None ) :
2010-01-18 08:38:26 +00:00
if not context :
2009-07-27 09:08:20 +00:00
context = { }
2010-01-18 08:38:26 +00:00
if context . get ( ' flag ' , False ) :
self . create_picking ( cr , uid , ids , context = { } )
self . write ( cr , uid , ids , { ' state ' : ' paid ' } )
else :
context [ ' flag ' ] = True
2008-08-24 14:45:43 +00:00
return True
def action_cancel ( self , cr , uid , ids , context = None ) :
self . write ( cr , uid , ids , { ' state ' : ' cancel ' } )
return True
def action_done ( self , cr , uid , ids , context = None ) :
2010-01-18 08:38:26 +00:00
for order in self . browse ( cr , uid , ids , context = context ) :
if not order . journal_entry :
self . create_account_move ( cr , uid , ids , context = { } )
2008-08-24 14:45:43 +00:00
return True
2010-01-18 08:38:26 +00:00
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 , ) )
return [ name for id , name in cr . fetchall ( ) ]
2008-08-24 14:45:43 +00:00
pos_order ( )
2010-04-23 14:57:42 +00:00
class account_bank_statement ( osv . osv ) :
_inherit = ' account.bank.statement '
_columns = {
' 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
}
account_bank_statement ( )
class account_bank_statement_line ( osv . osv ) :
_inherit = ' account.bank.statement.line '
def _get_statement_journal ( self , cr , uid , ids , context , * a ) :
res = { }
for line in self . browse ( cr , uid , ids ) :
res [ line . id ] = line . statement_id and line . statement_id . journal_id and line . statement_id . journal_id . name or None
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 ' ) ,
}
account_bank_statement_line ( )
2008-08-24 14:45:43 +00:00
class pos_order_line ( osv . osv ) :
_name = " pos.order.line "
_description = " Lines of Point of Sale "
2010-01-18 08:38:26 +00:00
def _get_amount ( self , cr , uid , ids , field_name , arg , context ) :
res = { }
for line in self . browse ( cr , uid , ids ) :
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
return res
def _amount_line_ttc ( self , cr , uid , ids , field_name , arg , context ) :
res = { }
account_tax_obj = self . pool . get ( ' account.tax ' )
for line in self . browse ( cr , uid , ids ) :
tax_amount = 0.0
taxes = [ t for t in line . product_id . taxes_id ]
computed_taxes = account_tax_obj . compute ( cr , uid , taxes , line . price_unit , line . qty )
for tax in computed_taxes :
tax_amount + = tax [ ' amount ' ]
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 )
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 ] = res [ line . id ] + tax_amount
return res
2008-08-24 14:45:43 +00:00
def _amount_line ( self , cr , uid , ids , field_name , arg , context ) :
res = { }
2010-01-18 08:38:26 +00:00
2008-08-24 14:45:43 +00:00
for line in self . browse ( cr , uid , ids ) :
2010-01-18 08:38:26 +00:00
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 )
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
2008-08-24 14:45:43 +00:00
return res
def price_by_product ( self , cr , uid , ids , pricelist , product_id , qty = 0 , partner_id = False ) :
if not product_id :
return 0.0
if not pricelist :
2009-03-06 22:18:24 +00:00
raise osv . except_osv ( _ ( ' No Pricelist ! ' ) ,
_ ( ' You have to select a pricelist in the sale form ! \n ' \
' Please set one before choosing a product. ' ) )
2010-05-24 05:30:38 +00:00
p_obj = self . pool . get ( ' product.product ' ) . browse ( cr , uid , [ product_id ] ) [ 0 ]
uom_id = p_obj . uom_po_id . id
2008-08-24 14:45:43 +00:00
price = self . pool . get ( ' product.pricelist ' ) . price_get ( cr , uid ,
2010-05-24 05:30:38 +00:00
[ pricelist ] , product_id , qty or 1.0 , partner_id , { ' uom ' : uom_id } ) [ pricelist ]
2010-05-24 08:02:24 +00:00
unit_price = price or p_obj . list_price
if unit_price is False :
2010-05-24 05:30:38 +00:00
raise osv . except_osv ( _ ( ' No valid pricelist line found ! ' ) ,
_ ( " Couldn ' t find a pricelist line matching this product " \
" and quantity. \n You have to change either the product, " \
" the quantity or the pricelist. " ) )
2010-05-24 08:02:24 +00:00
return unit_price
2010-05-24 05:30:38 +00:00
2008-08-24 14:45:43 +00:00
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 )
2010-01-18 08:38:26 +00:00
self . write ( cr , uid , ids , { ' price_unit ' : price } )
return { ' value ' : { ' price_unit ' : price } , ' qty ' : 1 }
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 = ' '
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 )
2010-04-24 05:09:53 +00:00
return { ' value ' : { ' discount ' : disc , ' price_unit ' : price_f } }
2010-01-18 08:38:26 +00:00
return { }
def onchange_ded ( self , cr , uid , ids , val_ded , price_u , * a ) :
pos_order = self . pool . get ( ' pos.order.line ' )
res_obj = self . pool . get ( ' res.users ' )
res_company = self . pool . get ( ' res.company ' )
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
if val > comp :
return { ' value ' : { ' discount ' : val , ' notice ' : ' ' } }
return { ' value ' : { ' discount ' : val } }
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 ' )
res_company = self . pool . get ( ' res.company ' )
company_disc = pos_order . browse ( cr , uid , ids )
if discount :
if not company_disc :
comp = res_obj . browse ( cr , uid , uid ) . company_id . company_discount or 0.0
else :
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
2008-08-24 14:45:43 +00:00
2010-01-18 08:38:26 +00:00
if discount > comp :
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 } }
else :
return { ' value ' : { ' notice ' : ' No Discount ' , ' price_ded ' : price * discount * 0.01 or 0.0 } }
2008-08-24 14:45:43 +00:00
_columns = {
' name ' : fields . char ( ' Line Description ' , size = 512 ) ,
2010-01-18 08:38:26 +00:00
' 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 ) ,
2008-08-24 14:45:43 +00:00
' product_id ' : fields . many2one ( ' product.product ' , ' Product ' , domain = [ ( ' sale_ok ' , ' = ' , True ) ] , required = True , change_default = True ) ,
2010-01-18 08:38:26 +00:00
' price_unit ' : fields . function ( _get_amount , method = True , string = ' Unit Price ' , store = True ) ,
2010-04-26 10:30:38 +00:00
' price_ded ' : fields . float ( ' Discount(Amount) ' , digits_compute = dp . get_precision ( ' Point Of Sale ' ) ) ,
2008-08-24 14:45:43 +00:00
' qty ' : fields . float ( ' Quantity ' ) ,
2010-01-18 08:38:26 +00:00
' qty_rfd ' : fields . float ( ' Refunded Quantity ' ) ,
' price_subtotal ' : fields . function ( _amount_line , method = True , string = ' Subtotal w/o Tax ' ) ,
' price_subtotal_incl ' : fields . function ( _amount_line_ttc , method = True , string = ' Subtotal ' ) ,
2008-08-24 14:45:43 +00:00
' discount ' : fields . float ( ' Discount ( % ) ' , digits = ( 16 , 2 ) ) ,
2010-01-18 08:38:26 +00:00
' order_id ' : fields . many2one ( ' pos.order ' , ' Order Ref ' , ondelete = ' cascade ' ) ,
2009-01-27 11:15:46 +00:00
' create_date ' : fields . datetime ( ' Creation Date ' , readonly = True ) ,
2008-08-24 14:45:43 +00:00
}
_defaults = {
' name ' : lambda obj , cr , uid , context : obj . pool . get ( ' ir.sequence ' ) . get ( cr , uid , ' pos.order.line ' ) ,
' qty ' : lambda * a : 1 ,
' discount ' : lambda * a : 0.0 ,
2010-01-18 08:38:26 +00:00
' price_ded ' : lambda * a : 0.0 ,
' notice ' : lambda * a : ' No Discount ' ,
' company_id ' : lambda self , cr , uid , c : self . pool . get ( ' res.users ' ) . browse ( cr , uid , uid , c ) . company_id . id ,
2008-08-24 14:45:43 +00:00
}
def create ( self , cr , user , vals , context = { } ) :
if vals . get ( ' product_id ' ) :
return super ( pos_order_line , self ) . create ( cr , user , vals , context )
return False
def write ( self , cr , user , ids , values , context = { } ) :
if ' product_id ' in values and not values [ ' product_id ' ] :
return False
return super ( pos_order_line , self ) . write ( cr , user , ids , values , context )
2008-12-20 19:33:44 +00:00
def _scan_product ( self , cr , uid , ean , qty , order ) :
# search pricelist_id
pricelist_id = self . pool . get ( ' pos.order ' ) . read ( cr , uid , [ order ] , [ ' pricelist_id ' ] )
if not pricelist_id :
return False
new_line = True
product_id = self . pool . get ( ' product.product ' ) . search ( cr , uid , [ ( ' ean13 ' , ' = ' , ean ) ] )
if not product_id :
2010-01-18 08:38:26 +00:00
return False
2008-12-20 19:33:44 +00:00
# search price product
product = self . pool . get ( ' product.product ' ) . 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 ) ] )
if order_line_ids :
new_line = False
order_line_id = order_line_ids [ 0 ]
qty + = self . read ( cr , uid , order_line_ids [ 0 ] , [ ' qty ' ] ) [ ' qty ' ]
if new_line :
vals = { ' product_id ' : product_id [ 0 ] ,
' price_unit ' : price ,
' qty ' : qty ,
' name ' : product_name ,
' order_id ' : order ,
}
line_id = self . create ( cr , uid , vals )
if not line_id :
2010-04-24 05:09:53 +00:00
raise osv . except_osv ( _ ( ' Error ' ) , _ ( ' Create line failed ! ' ) )
2008-12-20 19:33:44 +00:00
else :
vals = {
' qty ' : qty ,
' price_unit ' : price
}
line_id = self . write ( cr , uid , order_line_id , vals )
if not line_id :
2010-01-18 08:38:26 +00:00
raise wizard . except_wizard ( _ ( ' Error ' ) , _ ( ' Modify line failed ! ' ) )
2008-12-20 19:33:44 +00:00
line_id = order_line_id
price_line = float ( qty ) * float ( price )
return { ' name ' : product_name , ' product_id ' : product_id [ 0 ] , ' price ' : price , ' price_line ' : price_line , ' qty ' : qty }
2009-12-29 12:49:21 +00:00
2008-08-24 14:45:43 +00:00
pos_order_line ( )
class pos_payment ( osv . osv ) :
_name = ' pos.payment '
_description = ' Pos Payment '
def _journal_get ( self , cr , uid , context = { } ) :
obj = self . pool . get ( ' account.journal ' )
ids = obj . search ( cr , uid , [ ( ' type ' , ' = ' , ' cash ' ) ] )
res = obj . read ( cr , uid , ids , [ ' id ' , ' name ' ] , context )
res = [ ( r [ ' id ' ] , r [ ' name ' ] ) for r in res ]
return res
def _journal_default ( self , cr , uid , context = { } ) :
journal_list = self . pool . get ( ' account.journal ' ) . search ( cr , uid , [ ( ' type ' , ' = ' , ' cash ' ) ] )
if journal_list :
return journal_list [ 0 ]
else :
return False
_columns = {
' name ' : fields . char ( ' Description ' , size = 64 ) ,
2010-01-18 08:38:26 +00:00
' order_id ' : fields . many2one ( ' pos.order ' , ' Order Ref ' , required = True , ondelete = ' cascade ' ) ,
2008-08-24 14:45:43 +00:00
' journal_id ' : fields . many2one ( ' account.journal ' , " Journal " , required = True ) ,
2008-12-20 18:29:38 +00:00
' payment_id ' : fields . many2one ( ' account.payment.term ' , ' Payment Term ' , select = True ) ,
2009-01-27 11:15:46 +00:00
' payment_nb ' : fields . char ( ' Piece Number ' , size = 32 ) ,
' payment_name ' : fields . char ( ' Payment Name ' , size = 32 ) ,
' payment_date ' : fields . date ( ' Payment Date ' , required = True ) ,
2008-08-24 14:45:43 +00:00
' amount ' : fields . float ( ' Amount ' , required = True ) ,
}
_defaults = {
' name ' : lambda obj , cr , uid , context : obj . pool . get ( ' ir.sequence ' ) . get ( cr , uid , ' pos.payment ' ) ,
' journal_id ' : _journal_default ,
2008-12-20 18:29:38 +00:00
' payment_date ' : lambda * a : time . strftime ( ' % Y- % m- %d ' ) ,
2008-08-24 14:45:43 +00:00
}
def create ( self , cr , user , vals , context = { } ) :
if vals . get ( ' journal_id ' ) and vals . get ( ' amount ' ) :
return super ( pos_payment , self ) . create ( cr , user , vals , context )
return False
def write ( self , cr , user , ids , values , context = { } ) :
if ' amount ' in values and not values [ ' amount ' ] :
return False
if ' journal_id ' in values and not values [ ' journal_id ' ] :
return False
return super ( pos_payment , self ) . write ( cr , user , ids , values , context )
pos_payment ( )
2010-04-23 14:57:42 +00:00
class account_move_line ( osv . osv ) :
2010-04-24 05:09:53 +00:00
2010-04-23 14:57:42 +00:00
_inherit = ' account.move.line '
def create ( self , cr , user , vals , context = { } ) :
pos_obj = self . pool . get ( ' pos.order ' )
val_name = vals . get ( ' name ' , ' ' )
val_ref = vals . get ( ' ref ' , ' ' )
if ( val_name and ' POS ' in val_name ) and ( val_ref and ' PACK ' in val_ref ) :
aaa = re . search ( r ' Stock move. \ ((.*) \ ) ' , vals . get ( ' name ' ) )
name_pos = aaa . groups ( ) [ 0 ]
pos_id = name_pos . replace ( ' POS ' , ' ' )
if pos_id and pos_id . isdigit ( ) :
pos_curr = pos_obj . browse ( cr , user , int ( pos_id ) )
pos_curr = pos_curr and pos_curr . contract_number or ' '
vals [ ' ref ' ] = pos_curr or vals . get ( ' ref ' )
return super ( account_move_line , self ) . create ( cr , user , vals , context )
account_move_line ( )
class account_move ( osv . osv ) :
2010-04-24 05:09:53 +00:00
2010-04-23 14:57:42 +00:00
_inherit = ' account.move '
2010-04-24 05:09:53 +00:00
2010-04-23 14:57:42 +00:00
def create ( self , cr , user , vals , context = { } ) :
pos_obj = self . pool . get ( ' pos.order ' )
val_name = vals . get ( ' name ' , ' ' )
val_ref = vals . get ( ' ref ' , ' ' )
if ( val_name and ' POS ' in val_name ) and ( val_ref and ' PACK ' in val_ref ) :
aaa = re . search ( r ' Stock move. \ ((.*) \ ) ' , vals . get ( ' name ' ) )
name_pos = aaa . groups ( ) [ 0 ]
pos_id = name_pos . replace ( ' POS ' , ' ' )
if pos_id and pos_id . isdigit ( ) :
pos_curr = pos_obj . browse ( cr , user , int ( pos_id ) )
pos_curr = pos_curr and pos_curr . contract_number or ' '
vals [ ' ref ' ] = pos_curr or vals . get ( ' ref ' )
return super ( account_move , self ) . create ( cr , user , vals , context )
account_move ( )
2010-01-18 08:38:26 +00:00
class product_product ( osv . osv ) :
_inherit = ' product.product '
_columns = {
' income_pdt ' : fields . boolean ( ' Product for Incoming ' ) ,
' expense_pdt ' : fields . boolean ( ' Product for expenses ' ) ,
' am_out ' : fields . boolean ( ' Controle for Outgoing Operations ' ) ,
' disc_controle ' : fields . boolean ( ' Discount Controle ' ) ,
}
_defaults = {
' disc_controle ' : lambda * a : True ,
}
product_product ( )
2010-05-05 09:58:24 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: