-
-
Notifications
You must be signed in to change notification settings - Fork 992
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
300 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
bank-payment | ||
stock-logistics-workflow | ||
stock-logistics-transport | ||
account-closing | ||
|
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,60 @@ | ||
.. 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 | ||
|
||
====================================== | ||
Sale Automatic Workflow - Payment Mode | ||
====================================== | ||
|
||
This module is a glue for **Account Payment Sale** (of the OCA/bank-payment | ||
project) and **Sale Automatic Workflow**. | ||
|
||
When a payment mode is associated with an automatic workflow, this one | ||
is automatically selected for the sales orders using this method. | ||
|
||
Installation | ||
============ | ||
|
||
As soon as both **Account Payment Mode** and **Sale Automatic Workflow** | ||
are installed, this module is installed. | ||
|
||
Configuration | ||
============= | ||
|
||
The automatic workflow associated to a payment mode can be chosen in | ||
the configuration of the payment modes in the Invoicing configuration menu. | ||
|
||
Usage | ||
===== | ||
|
||
When a payment mode is selected on a sales order, if it has an | ||
automatic workflow, the sales order will use it. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Guewen Baconnier <guewen.baconnier@camptocamp.com> | ||
* Sodexis <dev@sodexis.com> | ||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
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 -*- | ||
# © 2016 Camptocamp SA, Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from . import models |
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 -*- | ||
# © 2016 Camptocamp SA, Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
{'name': 'Sale Automatic Workflow - Payment Mode', | ||
'version': '9.0.2.0.0', | ||
'author': 'Camptocamp,Sodexis,Odoo Community Association (OCA)', | ||
'license': 'AGPL-3', | ||
'category': 'Sales Management', | ||
'depends': ['sale_automatic_workflow', | ||
'account_payment_sale', # oca/bank-payment | ||
], | ||
'website': 'http://www.camptocamp.com', | ||
'data': ['data/automatic_workflow_data.xml', | ||
'views/account_payment_mode_views.xml', | ||
'views/sale_workflow_process_view.xml', | ||
], | ||
'installable': True, | ||
'auto_install': True, | ||
} |
24 changes: 24 additions & 0 deletions
24
sale_automatic_workflow_payment_mode/data/automatic_workflow_data.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,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
sale_automatic_workflow_payment_mode for Odoo | ||
Copyright (C) 2016 Sodexis | ||
The licence is in the file __openerp__.py | ||
--> | ||
<odoo> | ||
<data noupdate="1"> | ||
<record id="automatic_workflow_payment_filter" model="ir.filters"> | ||
<field name="name">Automatic Workflow Payment Filter</field> | ||
<field name="model_id">account.invoice</field> | ||
<field name="domain">[('state', '=', 'open')]</field> | ||
<field name="user_id" ref="base.user_root"/> | ||
</record> | ||
<record id="sale_automatic_workflow.automatic_validation" model="sale.workflow.process"> | ||
<field name="register_payment" eval="0" /> | ||
<field name="payment_filter_id" ref="automatic_workflow_payment_filter" /> | ||
</record> | ||
<record id="sale_automatic_workflow.manual_validation" model="sale.workflow.process"> | ||
<field name="register_payment" eval="0" /> | ||
<field name="payment_filter_id" ref="automatic_workflow_payment_filter" /> | ||
</record> | ||
</data> | ||
</odoo> |
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,8 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Camptocamp SA, Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from . import account_payment_mode | ||
from . import sale_order | ||
from . import sale_workflow_process | ||
from . import automatic_workflow_job |
14 changes: 14 additions & 0 deletions
14
sale_automatic_workflow_payment_mode/models/account_payment_mode.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,14 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Camptocamp SA, Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from openerp import fields, models | ||
|
||
|
||
class AccountPaymentMode(models.Model): | ||
_inherit = 'account.payment.mode' | ||
|
||
workflow_process_id = fields.Many2one( | ||
comodel_name='sale.workflow.process', | ||
string='Automatic Workflow' | ||
) |
49 changes: 49 additions & 0 deletions
49
sale_automatic_workflow_payment_mode/models/automatic_workflow_job.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,49 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Camptocamp SA, Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
import logging | ||
from openerp import models, api, fields | ||
from openerp.tools.safe_eval import safe_eval | ||
from openerp.addons.sale_automatic_workflow.models.automatic_workflow_job \ | ||
import commit | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class AutomaticWorkflowJob(models.Model): | ||
_inherit = 'automatic.workflow.job' | ||
|
||
@api.model | ||
def run_with_workflow(self, sale_wkf): | ||
workflow_domain = [('workflow_process_id', '=', sale_wkf.id)] | ||
res = super(AutomaticWorkflowJob, self).run_with_workflow(sale_wkf) | ||
if sale_wkf.register_payment: | ||
self._register_payments( | ||
safe_eval(sale_wkf.payment_filter_id.domain) + | ||
workflow_domain) | ||
return res | ||
|
||
@api.model | ||
def _register_payments(self, payment_filter): | ||
invoice_obj = self.env['account.invoice'] | ||
invoices = invoice_obj.search(payment_filter) | ||
_logger.debug('Invoices to Register Payment: %s', invoices.ids) | ||
for invoice in invoices: | ||
partner_type = invoice.type in ('out_invoice', 'out_refund') and \ | ||
'customer' or 'supplier' | ||
payment_mode = invoice.payment_mode_id | ||
with commit(self.env.cr): | ||
payment = self.env['account.payment'].create({ | ||
'invoice_ids': [(6, 0, invoice.ids)], | ||
'amount': invoice.residual, | ||
'payment_date': fields.Date.context_today(self), | ||
'communication': invoice.reference or invoice.number, | ||
'partner_id': invoice.partner_id.id, | ||
'partner_type': partner_type, | ||
'payment_type': payment_mode.payment_type, | ||
'payment_method_id': payment_mode.payment_method_id.id, | ||
'journal_id': payment_mode.fixed_journal_id.id, | ||
}) | ||
payment.post() | ||
return |
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,17 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from openerp import api, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = 'sale.order' | ||
|
||
@api.onchange('payment_mode_id') | ||
def onchange_payment_mode_set_workflow(self): | ||
if not self.payment_mode_id: | ||
return | ||
workflow = self.payment_mode_id.workflow_process_id | ||
if workflow: | ||
self.workflow_process_id = workflow |
34 changes: 34 additions & 0 deletions
34
sale_automatic_workflow_payment_mode/models/sale_workflow_process.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,34 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2016 Camptocamp SA, Sodexis | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) | ||
|
||
from openerp import models, fields, api | ||
|
||
|
||
class SaleWorkflowProcess(models.Model): | ||
_inherit = "sale.workflow.process" | ||
|
||
@api.model | ||
def _default_payment_filter_id(self): | ||
xmlid = ('sale_automatic_workflow_payment_mode.' | ||
'automatic_workflow_payment_filter') | ||
try: | ||
return self.env.ref(xmlid) | ||
except ValueError: | ||
return self.env['ir.filters'].browse() | ||
|
||
payment_filter_id = fields.Many2one( | ||
'ir.filters', | ||
string='Payment Filter', | ||
default=_default_payment_filter_id, | ||
) | ||
register_payment = fields.Boolean(string='Register Payment') | ||
payment_filter_domain = fields.Char( | ||
string='Payment Filter Domain', | ||
default="[('state', '=', 'open')]" | ||
) | ||
|
||
@api.onchange('payment_filter_id') | ||
def onchange_payment_filter_id(self): | ||
if self.payment_filter_id: | ||
self.payment_filter_domain = self.payment_filter_id.domain |
26 changes: 26 additions & 0 deletions
26
sale_automatic_workflow_payment_mode/views/account_payment_mode_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,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
|
||
<record id="account_payment_mode_form" model="ir.ui.view"> | ||
<field name="name">account.payment.mode.form</field> | ||
<field name="model">account.payment.mode</field> | ||
<field name="inherit_id" ref="account_payment_mode.account_payment_mode_form" /> | ||
<field name="arch" type="xml"> | ||
<group name="main" position="inside"> | ||
<field name="workflow_process_id" /> | ||
</group> | ||
</field> | ||
</record> | ||
|
||
<record id="account_payment_mode_tree" model="ir.ui.view"> | ||
<field name="name">account.payment.mode.tree</field> | ||
<field name="model">account.payment.mode</field> | ||
<field name="inherit_id" ref="account_payment_mode.account_payment_mode_tree" /> | ||
<field name="arch" type="xml"> | ||
<field name="payment_method_id" position="after"> | ||
<field name="workflow_process_id" /> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
42 changes: 42 additions & 0 deletions
42
sale_automatic_workflow_payment_mode/views/sale_workflow_process_view.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,42 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
sale_automatic_workflow_payment_mode for Odoo | ||
Copyright (C) 2016 Sodexis <dev@sodexis.com> | ||
The licence is in the file __openerp__.py --> | ||
|
||
<odoo> | ||
<record id="sale_workflow_process_view_form" model="ir.ui.view"> | ||
<field name="name">sale.order.form.automatic.inherit</field> | ||
<field name="model">sale.workflow.process</field> | ||
<field name="inherit_id" ref="sale_automatic_workflow.sale_workflow_process_view_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='sale_done']" position="before"> | ||
<field name="register_payment" /> | ||
<label for="payment_filter_id" | ||
attrs="{'required':[('register_payment','=',True)], 'invisible':[('register_payment','!=',True)]}" /> | ||
<div | ||
attrs="{'required':[('register_payment','=',True)], 'invisible':[('register_payment','!=',True)]}"> | ||
<field name="payment_filter_domain" /> | ||
<div class="oe_edit_only oe_inline"> | ||
Set selection based on a search filter: | ||
<field name="payment_filter_id" | ||
domain="[('model_id', '=', 'account.invoice')]" | ||
class="oe_inline" | ||
context="{'default_model_id': 'account.invoice', 'default_active': False, 'active_test': False}" | ||
can_create="true" can_write="true" /> | ||
</div> | ||
</div> | ||
</xpath> | ||
</field> | ||
</record> | ||
<record id="sale_workflow_process_view_tree" model="ir.ui.view"> | ||
<field name="name">sale_workflow_process.tree.inherit</field> | ||
<field name="model">sale.workflow.process</field> | ||
<field name="inherit_id" ref="sale_automatic_workflow.sale_workflow_process_view_tree" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='validate_invoice']" position="after"> | ||
<field name="register_payment" /> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |