Forward port of branch 7.0 up to b3485fb
authorMartin Trigaux <mat@openerp.com>
Fri, 3 Oct 2014 13:17:36 +0000 (15:17 +0200)
committerMartin Trigaux <mat@openerp.com>
Fri, 3 Oct 2014 13:17:36 +0000 (15:17 +0200)
1  2 
addons/account_anglo_saxon/invoice.py
addons/event/event.py

@@@ -111,29 -106,27 +111,33 @@@ class account_invoice_line(osv.osv)
                          for line in res:
                              if line.get('invl_id', 0) == i_line.id and a == line['account_id']:
                                  uom = i_line.product_id.uos_id or i_line.product_id.uom_id
 -                                standard_price = self.pool.get('product.uom')._compute_price(cr, uid, uom.id, i_line.product_id.standard_price, i_line.uos_id.id)
 +                                valuation_price_unit = self.pool.get('product.uom')._compute_price(cr, uid, uom.id, i_line.product_id.standard_price, i_line.uos_id.id)
 +                                if i_line.product_id.cost_method != 'standard' and i_line.purchase_line_id:
 +                                    #for average/fifo/lifo costing method, fetch real cost price from incomming moves
 +                                    stock_move_obj = self.pool.get('stock.move')
 +                                    valuation_stock_move = stock_move_obj.search(cr, uid, [('purchase_line_id', '=', i_line.purchase_line_id.id)], limit=1, context=context)
 +                                    if valuation_stock_move:
 +                                        valuation_price_unit = stock_move_obj.browse(cr, uid, valuation_stock_move[0], context=context).price_unit
                                  if inv.currency_id.id != company_currency:
 -                                    standard_price = self.pool.get('res.currency').compute(cr, uid, company_currency, inv.currency_id.id, standard_price, context={'date': inv.date_invoice})
 -                                if standard_price != i_line.price_unit and line['price_unit'] == i_line.price_unit and acc:
 +                                    valuation_price_unit = self.pool.get('res.currency').compute(cr, uid, company_currency, inv.currency_id.id, valuation_price_unit, context={'date': inv.date_invoice})
 +                                if valuation_price_unit != i_line.price_unit and line['price_unit'] == i_line.price_unit and acc:
-                                     price_diff = round(i_line.price_unit - valuation_price_unit, account_prec)
-                                     line.update({'price': round(valuation_price_unit * line['quantity'], account_prec)})
+                                     # price with discount and without tax included
+                                     price_unit = self.pool['account.tax'].compute_all(cr, uid, line['taxes'],
+                                         i_line.price_unit * (1-(i_line.discount or 0.0)/100.0), line['quantity'])['total']
 -                                    price_line = round(standard_price * line['quantity'], account_prec)
++                                    price_line = round(valuation_price_unit * line['quantity'], account_prec)
+                                     price_diff = round(price_unit - price_line, account_prec)
+                                     line.update({'price': price_line})
                                      diff_res.append({
 -                                        'type':'src',
 +                                        'type': 'src',
                                          'name': i_line.name[:64],
-                                         'price_unit': price_diff,
+                                         'price_unit': round(price_diff / line['quantity'], account_prec),
 -                                        'quantity':line['quantity'],
 +                                        'quantity': line['quantity'],
-                                         'price': round(price_diff * line['quantity'], account_prec),
+                                         'price': price_diff,
 -                                        'account_id':acc,
 -                                        'product_id':line['product_id'],
 -                                        'uos_id':line['uos_id'],
 -                                        'account_analytic_id':line['account_analytic_id'],
 -                                        'taxes':line.get('taxes',[]),
 +                                        'account_id': acc,
 +                                        'product_id': line['product_id'],
 +                                        'uos_id': line['uos_id'],
 +                                        'account_analytic_id': line['account_analytic_id'],
 +                                        'taxes': line.get('taxes', []),
                                          })
                          res += diff_res
          return res
@@@ -91,15 -93,28 +91,15 @@@ class event_event(osv.osv)
      def button_done(self, cr, uid, ids, context=None):
          return self.write(cr, uid, ids, {'state': 'done'}, context=context)
  
 -    def check_registration_limits(self, cr, uid, ids, context=None):
 -        for self.event in self.browse(cr, uid, ids, context=context):
 -            total_confirmed = self.event.register_current
 -            if total_confirmed < self.event.register_min or total_confirmed > self.event.register_max and self.event.register_max!=0:
 -                raise osv.except_osv(_('Error!'),_("The total of confirmed registration for the event '%s' does not meet the expected minimum/maximum. Please reconsider those limits before going further.") % (self.event.name))
 -
 -    def check_registration_limits_before(self, cr, uid, ids, no_of_registration, context=None):
 -        for event in self.browse(cr, uid, ids, context=context):
 -            available_seats = event.register_avail
 -            if available_seats and no_of_registration > available_seats:
 -                raise osv.except_osv(_('Warning!'),_("Only %d Seats are Available!") % (available_seats))
 -            elif available_seats == 0:
 -                raise osv.except_osv(_('Warning!'),_("No Tickets Available!"))
 -
      def confirm_event(self, cr, uid, ids, context=None):
          register_pool = self.pool.get('event.registration')
 -        if self.event.email_confirmation_id:
 -        #send reminder that will confirm the event for all the people that were already confirmed
 -            reg_ids = register_pool.search(cr, uid, [
 -                               ('event_id', '=', self.event.id),
 -                               ('state', 'not in', ['draft', 'cancel'])], context=context)
 -            register_pool.mail_user_confirm(cr, uid, reg_ids, context=context)
 +        for event in self.browse(cr, uid, ids, context=context):
 +            if event.email_confirmation_id:
 +            #send reminder that will confirm the event for all the people that were already confirmed
 +                reg_ids = register_pool.search(cr, uid, [
 +                                   ('event_id', '=', event.id),
 +                                   ('state', 'not in', ['draft', 'cancel'])], context=context)
-                 register_pool.mail_user_confirm(cr, uid, reg_ids)
++                register_pool.mail_user_confirm(cr, uid, reg_ids, context=context)
          return self.write(cr, uid, ids, {'state': 'confirm'}, context=context)
  
      def button_confirm(self, cr, uid, ids, context=None):