mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Merge pull request #232 from acsone/8.0-imp-payment-blocking-draft-invoice-ape
[IMP][account_payment_blocking] Allow to set no follow up on draft invoices
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
##############################################################################
|
||||
{
|
||||
'name': 'account banking payment blocking',
|
||||
'version': '8.0.0.1.0',
|
||||
'version': '8.0.1.0.0',
|
||||
'category': 'Banking addons',
|
||||
'summary': """
|
||||
Prevent invoices under litigation to be proposed in payment orders.
|
||||
|
||||
@@ -33,6 +33,21 @@ class account_invoice(orm.Model):
|
||||
('invoice.id', '=', invoice_id)],
|
||||
context=context)
|
||||
|
||||
def _update_blocked(self, cr, uid, invoice, value, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
else:
|
||||
context = context.copy()
|
||||
if invoice.move_id.id:
|
||||
move_line_ids = self._get_move_line(cr, uid, invoice.id,
|
||||
context=context)
|
||||
assert len(move_line_ids) == 1
|
||||
# work with account_constraints from OCA/AFT:
|
||||
context.update({'from_parent_object': True})
|
||||
self.pool.get('account.move.line')\
|
||||
.write(cr, uid, move_line_ids, {'blocked': value},
|
||||
context=context)
|
||||
|
||||
def _set_move_blocked(self, cr, uid, ids, name, field_value, arg,
|
||||
context=None):
|
||||
if context is None:
|
||||
@@ -40,15 +55,16 @@ class account_invoice(orm.Model):
|
||||
if isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
for invoice in self.browse(cr, uid, ids, context=context):
|
||||
if invoice.move_id.id:
|
||||
move_line_ids = self._get_move_line(cr, uid, invoice.id,
|
||||
context=context)
|
||||
assert len(move_line_ids) == 1
|
||||
# work with account_constraints from OCA/AFT:
|
||||
context.update({'from_parent_object': True})
|
||||
self.pool.get('account.move.line')\
|
||||
.write(cr, uid, move_line_ids, {'blocked': field_value},
|
||||
context=context)
|
||||
self._update_blocked(cr, uid, invoice, field_value,
|
||||
context=context)
|
||||
|
||||
def action_move_create(self, cr, uid, ids, context=None):
|
||||
res = super(account_invoice, self).action_move_create(cr, uid, ids,
|
||||
context=context)
|
||||
for invoice in self.browse(cr, uid, ids, context=context):
|
||||
self._update_blocked(cr, uid, invoice, invoice.draft_blocked,
|
||||
context=context)
|
||||
return res
|
||||
|
||||
def _get_move_blocked(self, cr, uid, ids, name, arg, context=None):
|
||||
res = {}
|
||||
@@ -72,4 +88,5 @@ class account_invoice(orm.Model):
|
||||
type='boolean', string='No Follow Up',
|
||||
states={'draft': [('readonly',
|
||||
True)]}),
|
||||
'draft_blocked': fields.boolean(string='No Follow Up'),
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ class TestAccountBankingPaymentBlocking(common.TransactionCase):
|
||||
move_line_obj = self.registry('account.move.line')
|
||||
invoice_id = create_simple_invoice(self, self.cr, self.uid,
|
||||
context=self.context)
|
||||
invoice_obj.write(self.cr, self.uid, [invoice_id],
|
||||
{'draft_blocked': True})
|
||||
workflow.trg_validate(self.uid, 'account.invoice', invoice_id,
|
||||
'invoice_open', self.cr)
|
||||
invoice = invoice_obj.browse(self.cr, self.uid, [invoice_id],
|
||||
@@ -66,10 +68,11 @@ class TestAccountBankingPaymentBlocking(common.TransactionCase):
|
||||
['payable', 'receivable']),
|
||||
('invoice.id', '=', invoice.id)])
|
||||
move_line = move_line_obj.browse(self.cr, self.uid, move_line_ids)[0]
|
||||
self.assertTrue(move_line.blocked)
|
||||
self.assertEqual(invoice.blocked, move_line.blocked,
|
||||
'Blocked values are not equals')
|
||||
move_line_obj.write(self.cr, self.uid, move_line_ids,
|
||||
{'blocked': True})
|
||||
{'blocked': False})
|
||||
invoice = invoice_obj.browse(self.cr, self.uid, [invoice_id],
|
||||
context=self.context)[0]
|
||||
move_line = move_line_obj.browse(self.cr, self.uid, move_line_ids)[0]
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
<field name="inherit_id" ref="account.invoice_supplier_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="move_id" position="after">
|
||||
<field name="blocked"/>
|
||||
<field name="blocked" attrs="{'invisible': [('move_id', '=', False)]}"/>
|
||||
<field name="draft_blocked" attrs="{'invisible': [('move_id', '!=', False)]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user