Skip to content

Commit

Permalink
[ADD][8.0] stock_picking_account_policy
Browse files Browse the repository at this point in the history
  • Loading branch information
andhit-r committed Mar 11, 2017
1 parent 74f0678 commit 2415622
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 0 deletions.
49 changes: 49 additions & 0 deletions stock_picking_account_policy/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.. 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

============================
Stock Picking Account Policy
============================

Manage picking's workflow button invisibility by groups


Installation
============

To install this module, you need to:

1. Clone the branch 8.0 of the repository https://github.com/open-synergy/opnsynid-stock-logistics-workflow
2. Add the path to this repository in your configuration (addons-path)
3. Update the module list
4. Go to menu *Setting -> Modules -> Local Modules*
5. Search For *Stock Picking Account Policy*
6. Install the module

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/open-synergy/opnsynid-stock-logistics-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed
and welcomed feedback.


Credits
=======

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

* Andhitia Rama <andhitia.r@gmail.com>

Maintainer
----------

.. image:: https://opensynergy-indonesia.com/logo.png
:alt: OpenSynergy Indonesia
:target: https://opensynergy-indonesia.com

This module is maintained by the OpenSynergy Indonesia.
5 changes: 5 additions & 0 deletions stock_picking_account_policy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
21 changes: 21 additions & 0 deletions stock_picking_account_policy/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Stock Picking Account Policy",
"version": "8.0.1.0.0",
"category": "Stock Management",
"website": "https://opensynergy-indonesia.com",
"author": "OpenSynergy Indonesia",
"license": "AGPL-3",
"installable": True,
"depends": [
"stock_picking_policy",
"stock_account",
],
"data": [
"views/stock_picking_type_views.xml",
"views/stock_picking_views.xml",
],
"auto_install": True,
}
6 changes: 6 additions & 0 deletions stock_picking_account_policy/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import stock_picking_type
from . import stock_picking
43 changes: 43 additions & 0 deletions stock_picking_account_policy/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, api, fields


class StockPicking(models.Model):
_inherit = "stock.picking"

@api.multi
@api.depends(
"picking_type_id.invoice_group_ids",
)
def _compute_policy(self):
super(StockPicking, self)._compute_policy()
obj_picking_type = self.env["stock.picking.type"]
for picking in self:
picking.invoice_ok = False
picking_id = self.env.context.get("default_picking_type_id", False)
if not picking_id:
continue
picking_type = obj_picking_type.browse([picking_id])[0]
picking.invoice_ok = self._invoice_policy(picking_type)

@api.model
def _invoice_policy(self, picking_type):
result = False
user = self.env.user
invoice_group_ids = picking_type.invoice_group_ids.ids
group_ids = user.groups_id.ids
if not picking_type.invoice_group_ids.ids:
result = True
else:
if (set(invoice_group_ids) & set(group_ids)):
result = True
return result

invoice_ok = fields.Boolean(
string="Can Invoice",
compute="_compute_policy",
store=False,
)
17 changes: 17 additions & 0 deletions stock_picking_account_policy/models/stock_picking_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Copyright 2017 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, fields


class StockPickingType(models.Model):
_inherit = "stock.picking.type"

invoice_group_ids = fields.Many2many(
string="Allowed to Invoice",
comodel_name="res.groups",
rel="rel_picking_invoice",
col1="type_id",
col2="group_id",
)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions stock_picking_account_policy/views/stock_picking_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="stock_picking_type_view_form" model="ir.ui.view">
<field name="name">Stock Picking Type Policy Form</field>
<field name="model">stock.picking.type</field>
<field name="inherit_id" ref="stock_picking_policy.stock_picking_type_view_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//group[@name='grp_policy']" position="inside">
<field name="invoice_group_ids" widget="many2many_tags"/>
</xpath>
</data>
</field>
</record>
</data>
</openerp>
32 changes: 32 additions & 0 deletions stock_picking_account_policy/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="stock_picking_view_1_form" model="ir.ui.view">
<field name="name">Stock Picking Policy Form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock_account.view_picking_inherit_form2"/>
<field name="arch" type="xml">
<data>
<xpath expr="//button[@name='%(stock_account.action_stock_invoice_onshipping)d']" position="attributes">
<attribute name="groups"/>
<attribute name="attrs">{'invisible':['|','|',('state','!=','done'),('invoice_state','!=','2binvoiced'),('invoice_ok','=',True)]}</attribute>
<attribute name="states"/>
</xpath>
</data>
</field>
</record>

<record id="stock_picking_view_2_form" model="ir.ui.view">
<field name="name">Stock Picking Policy Form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock_picking_policy.stock_picking_view_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='unreserve_ok']" position="after">
<field name="invoice_ok"/>
</xpath>
</data>
</field>
</record>
</data>
</openerp>

0 comments on commit 2415622

Please sign in to comment.