diff --git a/addons/account/account.py b/addons/account/account.py index caf1d68c45d..132bee96bce 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2281,8 +2281,13 @@ class account_model(osv.osv): if not line.partner_id: raise osv.except_osv(_('Error !'), _("Maturity date of entry line generated by model line '%s' of model '%s' is based on partner payment term!" \ "\nPlease define partner on it!")%(line.name, model.name)) - if line.partner_id.property_payment_term: + + payment_term_id = False + if model.journal_id.type in ('purchase', 'purchase_refund') and line.partner_id.property_supplier_payment_term: + payment_term_id = line.partner_id.property_supplier_payment_term.id + elif line.partner_id.property_payment_term: payment_term_id = line.partner_id.property_payment_term.id + if payment_term_id: pterm_list = pt_obj.compute(cr, uid, payment_term_id, value=1, date_ref=date_maturity) if pterm_list: pterm_list = [l[0] for l in pterm_list] diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index c6011979f8d..3965050a5a2 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -216,7 +216,7 @@ class account_invoice(osv.osv): 'date_invoice': fields.date('Invoice Date', readonly=True, states={'draft':[('readonly',False)]}, select=True, help="Keep empty to use the current date"), 'date_due': fields.date('Due Date', states={'paid':[('readonly',True)], 'open':[('readonly',True)], 'close':[('readonly',True)]}, select=True, help="If you use payment terms, the due date will be computed automatically at the generation "\ - "of accounting entries. If you keep the payment term and the due date empty, it means direct payment. The payment term may compute several due dates, for example 50% now, 50% in one month."), + "of accounting entries. If you want to force a due date, make sure that the payment term is not set on the invoice. If you keep the payment term and the due date empty, it means direct payment."), 'partner_id': fields.many2one('res.partner', 'Partner', change_default=True, readonly=True, required=True, states={'draft':[('readonly',False)]}), 'payment_term': fields.many2one('account.payment.term', 'Payment Term',readonly=True, states={'draft':[('readonly',False)]}, help="If you use payment terms, the due date will be computed automatically at the generation "\ @@ -468,10 +468,11 @@ class account_invoice(osv.osv): if type in ('out_invoice', 'out_refund'): acc_id = p.property_account_receivable.id + partner_payment_term = p.property_payment_term and p.property_payment_term.id or False else: acc_id = p.property_account_payable.id + partner_payment_term = p.property_supplier_payment_term and p.property_supplier_payment_term.id or False fiscal_position = p.property_account_position and p.property_account_position.id or False - partner_payment_term = p.property_payment_term and p.property_payment_term.id or False if p.bank_ids: bank_id = p.bank_ids[0].id @@ -733,6 +734,7 @@ class account_invoice(osv.osv): def action_date_assign(self, cr, uid, ids, *args): for inv in self.browse(cr, uid, ids): res = self.onchange_payment_term_date_invoice(cr, uid, inv.id, inv.payment_term.id, inv.date_invoice) + print "action_date_assign res=", res if res and res['value']: self.write(cr, uid, [inv.id], res['value']) return True diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 95b53b51339..00aa1d9a64d 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -652,17 +652,24 @@ class account_move_line(osv.osv): return {'value':val} if not date: date = datetime.now().strftime('%Y-%m-%d') + jt = False + if journal: + jt = journal_obj.browse(cr, uid, journal).type part = partner_obj.browse(cr, uid, partner_id) - if part.property_payment_term: - res = payment_term_obj.compute(cr, uid, part.property_payment_term.id, 100, date) + payment_term_id = False + if jt and jt in ('purchase', 'purchase_refund') and part.property_supplier_payment_term: + payment_term_id = part.property_supplier_payment_term.id + elif jt and part.property_payment_term: + payment_term_id = part.property_payment_term.id + if payment_term_id: + res = payment_term_obj.compute(cr, uid, payment_term_id, 100, date) if res: val['date_maturity'] = res[0][0] if not account_id: id1 = part.property_account_payable.id id2 = part.property_account_receivable.id - if journal: - jt = journal_obj.browse(cr, uid, journal).type + if jt: if jt in ('sale', 'purchase_refund'): val['account_id'] = fiscal_pos_obj.map_account(cr, uid, part and part.property_account_position or False, id2) elif jt in ('purchase', 'sale_refund'): diff --git a/addons/account/demo/account_demo.xml b/addons/account/demo/account_demo.xml index 0dff40ca19f..2cae1eb81a1 100644 --- a/addons/account/demo/account_demo.xml +++ b/addons/account/demo/account_demo.xml @@ -131,5 +131,21 @@ + + + + + + + + + + + + + + + + diff --git a/addons/account/partner.py b/addons/account/partner.py index 36fd88183f2..67f20b3f618 100644 --- a/addons/account/partner.py +++ b/addons/account/partner.py @@ -180,9 +180,16 @@ class res_partner(osv.osv): 'account.payment.term', type='many2one', relation='account.payment.term', - string ='Payment Term', + string ='Customer Payment Term', view_load=True, - help="This payment term will be used instead of the default one for the current partner"), + help="This payment term will be used instead of the default one for sale orders and customer invoices"), + 'property_supplier_payment_term': fields.property( + 'account.payment.term', + type='many2one', + relation='account.payment.term', + string ='Supplier Payment Term', + view_load=True, + help="This payment term will be used instead of the default one for purchase orders and supplier invoices"), 'ref_companies': fields.one2many('res.company', 'partner_id', 'Companies that refers to partner'), 'last_reconciliation_date': fields.datetime('Latest Reconciliation Date', help='Date on which the partner accounting entries were reconciled last time') diff --git a/addons/account/partner_view.xml b/addons/account/partner_view.xml index ec3dcba3b84..8f4f4f6f654 100644 --- a/addons/account/partner_view.xml +++ b/addons/account/partner_view.xml @@ -79,11 +79,12 @@ - + + diff --git a/addons/base_vat/base_vat_view.xml b/addons/base_vat/base_vat_view.xml index 1d7f06eb571..346bdd02d4f 100644 --- a/addons/base_vat/base_vat_view.xml +++ b/addons/base_vat/base_vat_view.xml @@ -7,7 +7,7 @@ res.partner - +