Skip to content
This repository has been archived by the owner on Oct 16, 2023. It is now read-only.

Commit

Permalink
Merge d225450 into 909ef5e
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Oct 19, 2018
2 parents 909ef5e + d225450 commit 5c28775
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 121 deletions.
35 changes: 35 additions & 0 deletions invoice_verified_state/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3


=============================================
GRAP - Invoices 'Verified' / 'To Check' state
=============================================

1. Add a 'Verified' state on account.invoice (supplier and supplier refund
invoices)

* Only Accounting managers can validate supplier account invoices
* the workflow is so modified

2. Add a 'To check' checkbox field on account move

* The setting is done per journal
* if a journal is set to 'To Check' all the accounting moves will be set as
'To Check'. this feature is usefull with the module to export to EBP, to
prevent import of moves that has not been controled by accounting managers.

Roadmap / Known Issues
======================

* rename the module into ```grap_invoice_state```

Credits
=======

Contributors
------------

* Sylvain LE GAL <https://twitter.com/legalsylvain>
* Julien WESTE
29 changes: 6 additions & 23 deletions invoice_verified_state/__openerp__.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
# -*- coding: utf-8 -*-
# coding: utf-8
# Copyright (C) 2013-Today: GRAP (<http://www.grap.coop/>)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# @author: Julien WESTE
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
'name': "Account - Invoice 'Verified' state",
'version': '7.0.1.0.0',
'category': 'Accounting',
'description': """
Add a 'Verified' state on account.invoice
=========================================
* Add a Verified state on account.invoice;
* Only Account_manager can validate supplier account.invoice;
* Modify the corresponding workflow;
Copyright, Author and Licence
-----------------------------
* Copyright : 2013, Groupement Régional Alimentaire de Proximité;
* Author :
* Julien WESTE;
* Licence : AGPL-3 (http://www.gnu.org/licenses/)
""",
'name': "GRAP - Invoices 'Verified' / 'To Check' state",
'version': '8.0.3.0.0',
'category': 'Custom',
'author': 'GRAP',
'website': 'http://www.grap.coop',
'license': 'AGPL-3',
'depends': [
'account',
'account_voucher',
],
'data': [
'views/account_invoice_view.xml',
'views/account_journal_view.xml',
'views/view_account_invoice.xml',
'views/view_account_journal.xml',
'data/workflow.xml',
],
'demo': [
Expand Down
14 changes: 14 additions & 0 deletions invoice_verified_state/demo/res_groups.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2013-Today: GRAP (<http://www.grap.coop/>)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
@author: Julien WESTE
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<openerp><data>

<record id="account.group_account_manager" model="res.groups">
<field name="user" eval="[(4, ref('base.user_root'))]" />
</record>

</data></openerp>
10 changes: 0 additions & 10 deletions invoice_verified_state/demo/res_groups.yml

This file was deleted.

23 changes: 23 additions & 0 deletions invoice_verified_state/migrations/8.0.3.0.0/pre-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# coding: utf-8
# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

__name__ = u"Precompute 'move_to_check' field of account_invoice"


def precompute_move_to_check(cr):
sql = """
ALTER TABLE account_invoice ADD COLUMN move_to_check BOOLEAN;
UPDATE account_invoice ai
SET move_to_check = am.to_check
FRoM account_move am
WHERE ai.move_id = am.id;
"""
cr.execute(sql)


def migrate(cr, version):
if not version:
return
precompute_move_to_check(cr)
2 changes: 1 addition & 1 deletion invoice_verified_state/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# coding: utf-8
from . import account_invoice
from . import account_journal
from . import account_move
84 changes: 18 additions & 66 deletions invoice_verified_state/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -1,83 +1,35 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2013-Today: GRAP (<http://www.grap.coop/>)
# coding: utf-8
# Copyright (C) 2013 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# @author: Julien WESTE
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.osv.orm import Model
from openerp.osv import fields
from openerp.osv import osv
from openerp.tools.translate import _

from openerp import _, api, fields, models
from openerp.exceptions import Warning as UserError

class AccountInvoice(Model):
_inherit = 'account.invoice'

_ACCOUNT_INVOICE_STATE = [
('draft', 'Draft'),
('verified', _('Verified')),
('proforma', 'Pro-forma'),
('proforma2', 'Pro-forma'),
('open', 'Open'),
('paid', 'Paid'),
('cancel', 'Cancelled'),
]

def _search_move_to_check(self, cr, uid, obj, name, arg, context=None):
am_obj = self.pool['account.move']
ai_obj = self.pool['account.invoice']
am_ids = am_obj.search(
cr, uid, [('to_check', '=', True)], context=context)
ai_ids = ai_obj.search(
cr, uid, [('move_id', 'in', am_ids)], context=context)
return [('id', 'in', ai_ids)]
class AccountInvoice(models.Model):
_inherit = 'account.invoice'

def button_move_check(self, cr, uid, ids, context=None):
am_obj = self.pool['account.move']
am_ids = []
for ai in self.browse(cr, uid, ids, context=context):
if ai.move_id:
am_ids.append(ai.move_id.id)
am_obj.write(cr, uid, am_ids, {'to_check': False}, context=context)
return True
move_to_check = fields.Boolean(
string='Move To Check', related='move_id.to_check', store=True)

def _get_move_to_check(self, cr, uid, ids, name, arg, context=None):
res = {}
for item in self.browse(cr, uid, ids, context=context):
res[item.id] = item.move_id and item.move_id.to_check or False
return res
state = fields.Selection(selection_add=[('verified', ('Verified'))])

_columns = {
'move_to_check': fields.function(
_get_move_to_check, type='boolean', string='Move To Check',
fnct_search=_search_move_to_check),
'state': fields.selection(
_ACCOUNT_INVOICE_STATE, string='State', select=True, readonly=True,
help="* The 'Draft' state is used when a user is encoding"
" a new and unconfirmed Invoice."
"\n* The 'Pro-forma' when invoice is in Pro-forma state,"
" invoice does not have an invoice number."
"\n* The 'Verified' state is used when the user has checked"
" that the invoice is conform to what he expected and is"
" ready to be processed by the accountants."
"\n* The 'Open' state is used when user create invoice,"
" a invoice number is generated.Its in open state till user"
" does not pay invoice."
"\n* The 'Paid' state is set automatically when the invoice"
" is paid. Its related journal entries may or may not be"
" reconciled."
"\n* The 'Cancelled' state is used when user cancel invoice."),
}
@api.multi
def button_move_check(self):
moves = self.mapped('move_id')
moves.write({'to_check': False})

def wkf_verify_invoice(self, cr, uid, ids, context=None):
for invoice in self.browse(cr, uid, ids, context=context):
@api.multi
def wkf_verify_invoice(self):
for invoice in self:
if not invoice.date_invoice or not invoice.date_due\
or not invoice.supplier_invoice_number:
raise osv.except_osv(_('Error!'), _(
raise UserError(_(
"Verify a supplier invoice requires to set the following"
" fields :\n"
"* 'Invoice Date';\n"
"* 'Due Date';\n"
"* 'Supplier Invoice Number';"))
self.write(cr, uid, ids, {'state': 'verified'})
return True
self.write({'state': 'verified'})
21 changes: 9 additions & 12 deletions invoice_verified_state/models/account_journal.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2013-Today: GRAP (<http://www.grap.coop/>)
# coding: utf-8
# Copyright (C) 2018 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# @author: Julien WESTE
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.osv import fields
from openerp.osv.orm import Model

from openerp import fields, models

class AccountJournal(Model):

class AccountJournal(models.Model):
_inherit = 'account.journal'

_columns = {
'move_to_check': fields.boolean(
string='Moves to Check', help="If you check this box,"
" account moves created in this journal"
" will be marked as 'To check by a financial manager'."),
}
move_to_check = fields.Boolean(
string='Moves to Check', help="If you check this box,"
" account moves created in this journal"
" will be marked as 'To check by a financial manager'.")
19 changes: 10 additions & 9 deletions invoice_verified_state/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2013-Today: GRAP (<http://www.grap.coop/>)
# coding: utf-8
# Copyright (C) 2013 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# @author: Julien WESTE
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp.osv.orm import Model
from openerp import api, models


class AccountMove(Model):
class AccountMove(models.Model):
_inherit = 'account.move'

def create(self, cr, uid, vals, context=None):
journal_obj = self.pool['account.journal']
@api.model
def create(self, vals):
AccountJournal = self.env['account.journal']
if vals.get('journal_id', False) and not vals.get('to_check'):
journal = journal_obj.browse(
cr, uid, vals['journal_id'], context=context)
journal = AccountJournal.browse(
vals['journal_id'])
vals['to_check'] = journal.move_to_check
return super(AccountMove, self).create(cr, uid, vals, context=context)
return super(AccountMove, self).create(vals)

0 comments on commit 5c28775

Please sign in to comment.