86 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Python
		
	
	
			
		
		
	
	
			86 lines
		
	
	
		
			3.6 KiB
		
	
	
	
		
			Python
		
	
	
| # -*- coding: utf-8 -*-
 | |
| ##############################################################################
 | |
| #
 | |
| #    OpenERP, Open Source Management Solution
 | |
| #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 | |
| #
 | |
| #    cam_invoice_skonto, Custom Module for OpenERP
 | |
| #    Copyright (C) 2014 Camadeus Consulting GmbH (<http://www.camadeus.at>).
 | |
| #
 | |
| #    This program is free software: you can redistribute it and/or modify
 | |
| #    it under the terms of the GNU Affero General Public License as
 | |
| #    published by the Free Software Foundation, either version 3 of the
 | |
| #    License, or (at your option) any later version.
 | |
| #
 | |
| #    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
 | |
| #    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 <http://www.gnu.org/licenses/>.
 | |
| #
 | |
| ##############################################################################
 | |
| 
 | |
| from openerp.osv import fields, osv
 | |
| from openerp import models, fields as f, api
 | |
| import openerp.addons.decimal_precision as dp
 | |
| from datetime import date, timedelta, datetime
 | |
| 
 | |
| class account_payment_term(osv.osv):
 | |
|     _inherit = 'account.payment.term'
 | |
| 
 | |
|     _columns = {
 | |
|         'netto_tage': fields.integer('Netto Tage'),
 | |
|         'skonto_tage': fields.integer('Skonto Tage'),
 | |
|         'skonto_prozent': fields.float('Skonto Prozent'),
 | |
|     }
 | |
|     
 | |
|     def write(self, cr, uid, ids, values, context=None):
 | |
|         if context is None:
 | |
|             context = {}
 | |
|         
 | |
|         tl_obj = self.pool.get('account.payment.term.line')
 | |
|         for pay_term in self.browse(cr, uid, ids, context=context):
 | |
|             # Delete old account.payment.term.line
 | |
|             for tl_id in pay_term.line_ids:
 | |
|                 tl_obj.unlink(cr, uid, tl_id.id, context=context)
 | |
|             # Create new account.payment.term.line based on netto_tage
 | |
|             days = 0
 | |
|             if('netto_tage' in values): 
 | |
|                 days = values['netto_tage']
 | |
|             else: 
 | |
|                 days = pay_term.netto_tage
 | |
|             values['line_ids'] = [(0,0, {'payment_id':pay_term.id, 'value': 'balance', 'days': days, 'days2':0})]
 | |
|             
 | |
|         return super(account_payment_term, self).write(cr, uid, ids, values, context=context)
 | |
|         
 | |
|     def create(self, cr, uid, vals, context=None):
 | |
|         if context is None:
 | |
|             context = {}
 | |
|             
 | |
|         new_id = super(account_payment_term, self).create(cr, uid, vals, context=context)
 | |
|         self.write(cr, uid, new_id, {'netto_tage': vals['netto_tage']}, context=context)
 | |
|         
 | |
|         return new_id
 | |
|             
 | |
| class account_invoice(models.Model):
 | |
|     _inherit = 'account.invoice'
 | |
| 
 | |
|     @api.one
 | |
|     def _skonto_betrag_inkl(self):
 | |
|         if self.payment_term and self.payment_term.skonto_prozent:
 | |
|             self.skonto_betrag_inkl = self.amount_total * (1 - self.payment_term.skonto_prozent/100.0)
 | |
| 
 | |
|     skonto_faelligkeit = f.Date(string=u'Skonto Fälligkeit', readonly=True)  
 | |
|     skonto_betrag_inkl = f.Float(string='Betrag inkl. Skonto', digits=dp.get_precision('Account'), readonly=True, compute='_skonto_betrag_inkl') 
 | |
|     
 | |
|     @api.multi
 | |
|     def action_skonto_faelligkeit_assign(self):
 | |
|         for inv in self:
 | |
|             if inv.payment_term and inv.payment_term.skonto_tage:
 | |
|                 inv.write({'skonto_faelligkeit': datetime.strptime(inv.date_invoice, '%Y-%m-%d') + timedelta(days=inv.payment_term.skonto_tage)})
 | |
|         return True       
 | |
|     
 | |
| # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 |