-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.0.1.0.0] stock_picking_manual_invoice_link
- Loading branch information
Showing
8 changed files
with
331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
.. 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 Manual Invoice Link | ||
================================= | ||
|
||
|
||
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-warehouse | ||
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 Manual Invoice Link* | ||
6. Install the module | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/open-synergy/opnsynid-stock-logistics-warehouse/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 | ||
------------ | ||
|
||
* Michael Viriyananda <viriyananda.michael@gmail.com> | ||
* 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2019 OpenSynergy Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import wizards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2019 OpenSynergy Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
# pylint: disable=locally-disabled, manifest-required-author | ||
{ | ||
"name": "Stock Picking Manual Invoice Link", | ||
"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_invoice_link", | ||
], | ||
"data": [ | ||
"wizards/stock_picking_manual_invoice_link.xml", | ||
"views/stock_picking_views.xml", | ||
], | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions
20
stock_picking_manual_invoice_link/views/stock_picking_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data noupdate="0"> | ||
<record id="stock_picking_view_form" model="ir.ui.view"> | ||
<field name="name">stock.picking form</field> | ||
<field name="model">stock.picking</field> | ||
<field name="inherit_id" ref="stock.view_picking_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//button[@name='action_cancel']" position="before"> | ||
<button | ||
name="%(stock_picking_manual_invoice_link_action)d" | ||
attrs="{'invisible':['|',('state','!=','done'),('invoice_state','!=','2binvoiced')]}" | ||
string="Manually Link Invoice" | ||
type="action" | ||
/> | ||
</xpath> | ||
</field> | ||
</record> | ||
</data> | ||
</openerp> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2019 OpenSynergy Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import stock_picking_manual_invoice_link |
189 changes: 189 additions & 0 deletions
189
stock_picking_manual_invoice_link/wizards/stock_picking_manual_invoice_link.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2019 OpenSynergy Indonesia | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from openerp import models, fields, api | ||
|
||
|
||
class StockPickingManualInvoiceLink(models.TransientModel): | ||
_name = "stock.picking_manual_invoice_link" | ||
_description = "Link Picking to Invoice Manually" | ||
|
||
@api.model | ||
def _default_picking_id(self): | ||
return self._context.get("active_id", False) | ||
|
||
picking_id = fields.Many2one( | ||
string="Picking", | ||
comodel_name="stock.picking", | ||
default=lambda self: self._default_picking_id(), | ||
) | ||
invoice_id = fields.Many2one( | ||
string="Invoice", | ||
comodel_name="account.invoice", | ||
) | ||
line_ids = fields.One2many( | ||
string="Detail", | ||
comodel_name="stock.picking_manual_invoice_link_line", | ||
inverse_name="wizard_id", | ||
) | ||
|
||
@api.multi | ||
def onchange_picking_id(self, picking_id): | ||
value = self._get_value_before_onchange_picking_id() | ||
domain = self._get_domain_before_onchange_picking_id() | ||
if picking_id: | ||
obj_picking = self.env["stock.picking"] | ||
picking = obj_picking.browse([picking_id])[0] | ||
value = self._get_value_after_onchange_picking_id(picking) | ||
domain = self._get_domain_after_onchange_picking_id(picking) | ||
return {"value": value, "domain": domain} | ||
|
||
@api.multi | ||
def _get_value_before_onchange_picking_id(self): | ||
return { | ||
"invoice_id": False, | ||
"line_ids": [], | ||
} | ||
|
||
@api.multi | ||
def _get_domain_before_onchange_picking_id(self): | ||
return {} | ||
|
||
@api.multi | ||
def _get_value_after_onchange_picking_id(self, picking): | ||
result = { | ||
"line_ids": self._get_stock_move_lines(picking), | ||
} | ||
return result | ||
|
||
@api.model | ||
def _get_stock_move_lines(self, picking): | ||
result = [] | ||
for line in picking.move_lines: | ||
result.append((0, 0, { | ||
"stock_move_id": line.id, | ||
})) | ||
return result | ||
|
||
@api.multi | ||
def _get_domain_after_onchange_picking_id(self, picking): | ||
partner = picking.partner_id | ||
result = { | ||
"invoice_id": [ | ||
("id", "=", 0), | ||
] | ||
} | ||
inv_type = self._map_picking_type_2_invoice_type(picking) | ||
if partner: | ||
result.update({ | ||
"invoice_id": [ | ||
("partner_id.commercial_partner_id.id", "=", partner.id), | ||
("state", "in", ["open", "paid"]), | ||
("picking_ids", "=", False), | ||
("type", "in", inv_type), | ||
] | ||
}) | ||
return result | ||
|
||
@api.model | ||
def _map_picking_type_2_invoice_type(self, picking): | ||
result = [] | ||
ptype = picking.picking_type_id | ||
if ptype.code == "outgoing": | ||
result = ["out_invoice", "in_refund"] | ||
elif ptype.code == "incoming": | ||
result = ["in_invoice", "out_refund"] | ||
return result | ||
|
||
@api.multi | ||
def button_confirm(self): | ||
self.ensure_one() | ||
picking = self.picking_id | ||
picking.write(self._prepare_picking_data()) | ||
for line in self.line_ids: | ||
line.stock_move_id.write(line._prepare_stock_move_data()) | ||
|
||
@api.multi | ||
def _prepare_picking_data(self): | ||
self.ensure_one() | ||
return { | ||
"invoice_ids": [(6, 0, [self.invoice_id.id])], | ||
"invoice_state": "invoiced", | ||
} | ||
|
||
@api.multi | ||
def _prepare_invoice_data(self): | ||
self.ensure_one() | ||
return { | ||
"picking_ids": [(6, 0, [self.picking_id.id])], | ||
} | ||
|
||
|
||
class StockPickingManualInvoiceLinkLine(models.TransientModel): | ||
_name = "stock.picking_manual_invoice_link_line" | ||
_description = "Link Picking to Invoice Manually Line" | ||
|
||
@api.multi | ||
@api.depends("stock_move_id") | ||
def _compute_stock_move(self): | ||
for line in self: | ||
move = line.stock_move_id | ||
line.product_id = move.product_id.id | ||
line.picking_qty = move.product_uom_qty | ||
|
||
wizard_id = fields.Many2one( | ||
string="Wizard", | ||
comodel_name="stock.picking_manual_invoice_link", | ||
) | ||
invoice_id = fields.Many2one( | ||
string="Invoice", | ||
comodel_name="account.invoice", | ||
related="wizard_id.invoice_id", | ||
store=False, | ||
) | ||
invoice_line_id = fields.Many2one( | ||
string="Invoice Line", | ||
comodel_name="account.invoice.line", | ||
) | ||
stock_move_id = fields.Many2one( | ||
string="Stock Move", | ||
comodel_name="stock.move", | ||
) | ||
product_id = fields.Many2one( | ||
string="Product", | ||
comodel_name="product.product", | ||
compute="_compute_stock_move", | ||
related=False, | ||
store=False, | ||
) | ||
invoice_qty = fields.Float( | ||
string="Invoice Qty.", | ||
compute="_compute_stock_move", | ||
related=False, | ||
store=False, | ||
) | ||
picking_qty = fields.Float( | ||
string="Picking Qty.", | ||
related="stock_move_id.product_uom_qty", | ||
) | ||
|
||
@api.onchange("invoice_id") | ||
def onchange_invoice_id(self): | ||
self.invoice_line_id = False | ||
|
||
@api.multi | ||
def _prepare_stock_move_data(self): | ||
self.ensure_one() | ||
result = { | ||
"invoice_line_ids": [(6, 0, [self.invoice_line_id.id])] | ||
} | ||
return result | ||
|
||
@api.multi | ||
def _prepare_invoice_line_data(self): | ||
self.ensure_one() | ||
result = { | ||
"move_line_ids": [(6, 0, [self.stock_move_id.id])] | ||
} | ||
return result |
44 changes: 44 additions & 0 deletions
44
stock_picking_manual_invoice_link/wizards/stock_picking_manual_invoice_link.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data> | ||
<record id="stock_picking_manual_invoice_link_view_form" model="ir.ui.view"> | ||
<field name="name">stock.picking_manual_invoice_link form</field> | ||
<field name="model">stock.picking_manual_invoice_link</field> | ||
<field name="arch" type="xml"> | ||
<form string="Reason for the cancellation"> | ||
<group name="group_1" colspan="4" col="2"> | ||
<field name="picking_id" required="1" on_change="onchange_picking_id(picking_id)" invisible="1"/> | ||
<field name="invoice_id" required="1" on_change="onchange_picking_id(picking_id)"/> | ||
</group> | ||
<field name="line_ids"> | ||
<tree editable="top"> | ||
<field name="invoice_id" invisible="1"/> | ||
<field name="stock_move_id" invisible="1"/> | ||
<field name="product_id" readonly="1"/> | ||
<field name="picking_qty" readonly="1"/> | ||
<field name="invoice_line_id" required="1" domain="[('invoice_id','=',invoice_id),('product_id','=',product_id),('quantity','=',picking_qty)]"/> | ||
</tree> | ||
</field> | ||
<footer> | ||
<button name="button_confirm" | ||
string="Confirm" type="object" | ||
class="oe_highlight"/> | ||
or | ||
<button string="Cancel" class="oe_link" | ||
special="cancel" /> | ||
</footer> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record id="stock_picking_manual_invoice_link_action" model="ir.actions.act_window"> | ||
<field name="name">Manual Link to Invoice</field> | ||
<field name="type">ir.actions.act_window</field> | ||
<field name="res_model">stock.picking_manual_invoice_link</field> | ||
<field name="view_type">form</field> | ||
<field name="view_mode">form</field> | ||
<field name="view_id" ref="stock_picking_manual_invoice_link_view_form"/> | ||
<field name="target">new</field> | ||
</record> | ||
</data> | ||
</openerp> |