Add a "Supplier Payment Term" on res.partner

Add payment term on purchase.order

bzr revid: alexis@via.ecp.fr-20120711111434-ih20ohy81bynn1wd
This commit is contained in:
Alexis de Lattre 2012-07-11 13:14:34 +02:00
parent e9c288b4bf
commit 42ffccfa96
12 changed files with 70 additions and 23 deletions

View File

@ -2281,8 +2281,13 @@ class account_model(osv.osv):
if not line.partner_id: 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!" \ 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)) "\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 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) pterm_list = pt_obj.compute(cr, uid, payment_term_id, value=1, date_ref=date_maturity)
if pterm_list: if pterm_list:
pterm_list = [l[0] for l in pterm_list] pterm_list = [l[0] for l in pterm_list]

View File

@ -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_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, '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 "\ 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)]}), '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)]}, '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 "\ 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'): if type in ('out_invoice', 'out_refund'):
acc_id = p.property_account_receivable.id acc_id = p.property_account_receivable.id
partner_payment_term = p.property_payment_term and p.property_payment_term.id or False
else: else:
acc_id = p.property_account_payable.id 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 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: if p.bank_ids:
bank_id = p.bank_ids[0].id 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): def action_date_assign(self, cr, uid, ids, *args):
for inv in self.browse(cr, uid, ids): 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) 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']: if res and res['value']:
self.write(cr, uid, [inv.id], res['value']) self.write(cr, uid, [inv.id], res['value'])
return True return True

View File

@ -652,17 +652,24 @@ class account_move_line(osv.osv):
return {'value':val} return {'value':val}
if not date: if not date:
date = datetime.now().strftime('%Y-%m-%d') 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) part = partner_obj.browse(cr, uid, partner_id)
if part.property_payment_term: payment_term_id = False
res = payment_term_obj.compute(cr, uid, part.property_payment_term.id, 100, date) 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: if res:
val['date_maturity'] = res[0][0] val['date_maturity'] = res[0][0]
if not account_id: if not account_id:
id1 = part.property_account_payable.id id1 = part.property_account_payable.id
id2 = part.property_account_receivable.id id2 = part.property_account_receivable.id
if journal: if jt:
jt = journal_obj.browse(cr, uid, journal).type
if jt in ('sale', 'purchase_refund'): 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) 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'): elif jt in ('purchase', 'sale_refund'):

View File

@ -131,5 +131,21 @@
<record id="base.user_demo" model="res.users"> <record id="base.user_demo" model="res.users">
<field name="groups_id" eval="[(4,ref('account.group_account_user'))]"/> <field name="groups_id" eval="[(4,ref('account.group_account_user'))]"/>
</record> </record>
<!-- Add payment term on some demo partners -->
<record id="base.res_partner_agrolait" model="res.partner">
<field name="property_payment_term" ref="account_payment_term_net"/>
</record>
<record id="base.res_partner_c2c" model="res.partner">
<field name="property_payment_term" ref="account_payment_term"/>
<field name="property_supplier_payment_term" ref="account_payment_term"/>
</record>
<record id="base.res_partner_4" model="res.partner">
<field name="property_supplier_payment_term" ref="account_payment_term_net"/>
</record>
<record id="base.res_partner_asus" model="res.partner">
<field name="property_supplier_payment_term" ref="account_payment_term"/>
</record>
</data> </data>
</openerp> </openerp>

View File

@ -180,9 +180,16 @@ class res_partner(osv.osv):
'account.payment.term', 'account.payment.term',
type='many2one', type='many2one',
relation='account.payment.term', relation='account.payment.term',
string ='Payment Term', string ='Customer Payment Term',
view_load=True, 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', 'ref_companies': fields.one2many('res.company', 'partner_id',
'Companies that refers to partner'), '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') 'last_reconciliation_date': fields.datetime('Latest Reconciliation Date', help='Date on which the partner accounting entries were reconciled last time')

View File

@ -79,11 +79,12 @@
<group col="4"> <group col="4">
<group string="Customer Accounting Properties" col="4"> <group string="Customer Accounting Properties" col="4">
<field name="property_account_receivable" groups="account.group_account_invoice" /> <field name="property_account_receivable" groups="account.group_account_invoice" />
<field name="property_account_position" widget="selection"/>
<field name="property_payment_term" widget="selection"/> <field name="property_payment_term" widget="selection"/>
<field name="property_account_position" widget="selection"/>
</group> </group>
<group string="Supplier Accounting Properties" col="4"> <group string="Supplier Accounting Properties" col="4">
<field name="property_account_payable" groups="account.group_account_invoice"/> <field name="property_account_payable" groups="account.group_account_invoice"/>
<field name="property_supplier_payment_term" widget="selection"/>
</group> </group>
<group string="Customer Credit" col="4"> <group string="Customer Credit" col="4">
<field name="credit"/> <field name="credit"/>

View File

@ -7,7 +7,7 @@
<field name="model">res.partner</field> <field name="model">res.partner</field>
<field name="inherit_id" ref="account.view_partner_property_form"/> <field name="inherit_id" ref="account.view_partner_property_form"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="property_account_payable" position="after" version="7.0"> <field name="property_supplier_payment_term" position="after" version="7.0">
<label for="vat"/> <label for="vat"/>
<div> <div>
<field name="vat" on_change="vat_change(vat)" placeholder="BE0477472702" class="oe_inline"/> <field name="vat" on_change="vat_change(vat)" placeholder="BE0477472702" class="oe_inline"/>

View File

@ -203,6 +203,7 @@ class purchase_order(osv.osv):
'purchase.order.line': (_get_order, None, 10), 'purchase.order.line': (_get_order, None, 10),
}, multi="sums",help="The total amount"), }, multi="sums",help="The total amount"),
'fiscal_position': fields.many2one('account.fiscal.position', 'Fiscal Position'), 'fiscal_position': fields.many2one('account.fiscal.position', 'Fiscal Position'),
'payment_term': fields.many2one('account.payment.term', 'Payment Term'),
'product_id': fields.related('order_line','product_id', type='many2one', relation='product.product', string='Product'), 'product_id': fields.related('order_line','product_id', type='many2one', relation='product.product', string='Product'),
'create_uid': fields.many2one('res.users', 'Responsible'), 'create_uid': fields.many2one('res.users', 'Responsible'),
'company_id': fields.many2one('res.company','Company',required=True,select=1), 'company_id': fields.many2one('res.company','Company',required=True,select=1),
@ -271,12 +272,17 @@ class purchase_order(osv.osv):
def onchange_partner_id(self, cr, uid, ids, partner_id): def onchange_partner_id(self, cr, uid, ids, partner_id):
partner = self.pool.get('res.partner') partner = self.pool.get('res.partner')
if not partner_id: if not partner_id:
return {'value':{'fiscal_position': False}} return {'value': {
'fiscal_position': False,
'payment_term': False,
}}
supplier_address = partner.address_get(cr, uid, [partner_id], ['default']) supplier_address = partner.address_get(cr, uid, [partner_id], ['default'])
supplier = partner.browse(cr, uid, partner_id) supplier = partner.browse(cr, uid, partner_id)
pricelist = supplier.property_product_pricelist_purchase.id return {'value': {
fiscal_position = supplier.property_account_position and supplier.property_account_position.id or False 'pricelist_id': supplier.property_product_pricelist_purchase.id,
return {'value':{'pricelist_id': pricelist, 'fiscal_position': fiscal_position}} 'fiscal_position': supplier.property_account_position and supplier.property_account_position.id or False,
'payment_term': supplier.property_supplier_payment_term.id or False,
}}
def view_invoice(self, cr, uid, ids, context=None): def view_invoice(self, cr, uid, ids, context=None):
''' '''
@ -462,7 +468,7 @@ class purchase_order(osv.osv):
'invoice_line': [(6, 0, inv_lines)], 'invoice_line': [(6, 0, inv_lines)],
'origin': order.name, 'origin': order.name,
'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id, 'fiscal_position': order.fiscal_position.id or order.partner_id.property_account_position.id,
'payment_term': order.partner_id.property_payment_term and order.partner_id.property_payment_term.id or False, 'payment_term': order.payment_term.id or False,
'company_id': order.company_id.id, 'company_id': order.company_id.id,
} }
inv_id = inv_obj.create(cr, uid, inv_data, context=context) inv_id = inv_obj.create(cr, uid, inv_data, context=context)
@ -1070,7 +1076,8 @@ class procurement_order(osv.osv):
'pricelist_id': pricelist_id, 'pricelist_id': pricelist_id,
'date_order': purchase_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT), 'date_order': purchase_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
'company_id': procurement.company_id.id, 'company_id': procurement.company_id.id,
'fiscal_position': partner.property_account_position and partner.property_account_position.id or False 'fiscal_position': partner.property_account_position and partner.property_account_position.id or False,
'payment_term': partner.property_supplier_payment_term.id or False,
} }
res[procurement.id] = self.create_procurement_purchase_order(cr, uid, procurement, po_vals, line_vals, context=context) res[procurement.id] = self.create_procurement_purchase_order(cr, uid, procurement, po_vals, line_vals, context=context)
self.write(cr, uid, [procurement.id], {'state': 'running', 'purchase_id': res[procurement.id]}) self.write(cr, uid, [procurement.id], {'state': 'running', 'purchase_id': res[procurement.id]})

View File

@ -248,6 +248,7 @@
<field name="invoiced"/> <field name="invoiced"/>
</group> </group>
<group> <group>
<field name="payment_term" widget="selection"/>
<field name="fiscal_position"/> <field name="fiscal_position"/>
</group> </group>
</group> </group>

View File

@ -59,6 +59,9 @@ class stock_picking(osv.osv):
invoice_vals = super(stock_picking, self)._prepare_invoice(cr, uid, picking, partner, inv_type, journal_id, context=context) invoice_vals = super(stock_picking, self)._prepare_invoice(cr, uid, picking, partner, inv_type, journal_id, context=context)
if picking.purchase_id: if picking.purchase_id:
invoice_vals['fiscal_position'] = picking.purchase_id.fiscal_position.id invoice_vals['fiscal_position'] = picking.purchase_id.fiscal_position.id
invoice_vals['payment_term'] = picking.purchase_id.payment_term.id
if picking.purchase_id.payment_term and context.get('date_inv'):
invoice_vals['date_due'] = self.pool.get('account.invoice').onchange_payment_term_date_invoice(cr, uid, [], picking.purchase_id.payment_term.id, context.get('invoice_date'))['value'].get('date_due')
return invoice_vals return invoice_vals
def get_currency_id(self, cursor, user, picking): def get_currency_id(self, cursor, user, picking):

View File

@ -74,10 +74,6 @@ class purchase_line_invoice(osv.osv_memory):
journal_id = account_jrnl_obj.search(cr, uid, [('type', '=', 'purchase')], context=None) journal_id = account_jrnl_obj.search(cr, uid, [('type', '=', 'purchase')], context=None)
journal_id = journal_id and journal_id[0] or False journal_id = journal_id and journal_id[0] or False
a = partner.property_account_payable.id a = partner.property_account_payable.id
if partner and partner.property_payment_term.id:
pay_term = partner.property_payment_term.id
else:
pay_term = False
inv = { inv = {
'name': name, 'name': name,
'origin': name, 'origin': name,
@ -89,7 +85,7 @@ class purchase_line_invoice(osv.osv_memory):
'invoice_line': [(6,0,lines_ids)], 'invoice_line': [(6,0,lines_ids)],
'currency_id' : orders[0].pricelist_id.currency_id.id, 'currency_id' : orders[0].pricelist_id.currency_id.id,
'comment': multiple_order_invoice_notes(orders), 'comment': multiple_order_invoice_notes(orders),
'payment_term': pay_term, 'payment_term': orders[0].payment_term.id,
'fiscal_position': partner.property_account_position.id 'fiscal_position': partner.property_account_position.id
} }
inv_id = invoice_obj.create(cr, uid, inv) inv_id = invoice_obj.create(cr, uid, inv)

View File

@ -987,8 +987,10 @@ class stock_picking(osv.osv):
partner = self.pool.get('res.partner').browse(cr, uid, partner, context=context) partner = self.pool.get('res.partner').browse(cr, uid, partner, context=context)
if inv_type in ('out_invoice', 'out_refund'): if inv_type in ('out_invoice', 'out_refund'):
account_id = partner.property_account_receivable.id account_id = partner.property_account_receivable.id
payment_term = partner.property_payment_term and partner.property_payment_term.id or False
else: else:
account_id = partner.property_account_payable.id account_id = partner.property_account_payable.id
payment_term = False # We don't copy the payment term on supplier inv.
comment = self._get_comment_invoice(cr, uid, picking) comment = self._get_comment_invoice(cr, uid, picking)
invoice_vals = { invoice_vals = {
'name': picking.name, 'name': picking.name,
@ -997,7 +999,7 @@ class stock_picking(osv.osv):
'account_id': account_id, 'account_id': account_id,
'partner_id': partner.id, 'partner_id': partner.id,
'comment': comment, 'comment': comment,
'payment_term': partner.property_payment_term and partner.property_payment_term.id or False, 'payment_term': payment_term,
'fiscal_position': partner.property_account_position.id, 'fiscal_position': partner.property_account_position.id,
'date_invoice': context.get('date_inv', False), 'date_invoice': context.get('date_inv', False),
'company_id': picking.company_id.id, 'company_id': picking.company_id.id,