Add module sale_confirm_wizard

This commit is contained in:
Alexis de Lattre
2017-05-11 22:23:54 +02:00
parent ac54c5cc75
commit f3fdbec140
6 changed files with 182 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import wizard

View File

@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Sale Confirm Wizard',
'version': '10.0.1.0.0',
'category': 'Sale Management',
'license': 'AGPL-3',
'summary': 'Open a wizard when you confirm a sale order to update important info',
'description': """
Sale Confirm Wizard
===================
When you confirm a quotation, Odoo will open a small wizard where you will be able to check and update important information:
* customer PO number,
* delivery address,
* invoicing address,
* payment terms.
This module has been developped because the experience has shown, when a sales assistant confirms a quotation in Odoo, it overlooks the important information written in the customer PO that may be different from the information of the quotation in Odoo, which causes many errors in delivery and invoicing.
This module has been written by Alexis de Lattre from Akretion
<alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['sale'],
'data': [
'wizard/sale_confirm_view.xml',
'sale_view.xml',
],
'installable': True,
}

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="view_order_form" model="ir.ui.view">
<field name="name">sale.confirm.wizard.sale_order_form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<button name="action_confirm" type="object" states="draft" position="attributes">
<attribute name="type">action</attribute>
<attribute name="name">%(sale_confirm_action)d</attribute>
</button>
<button name="action_confirm" type="object" states="sent" position="attributes">
<attribute name="type">action</attribute>
<attribute name="name">%(sale_confirm_action)d</attribute>
</button>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import sale_confirm

View File

@@ -0,0 +1,66 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api
class SaleConfirm(models.TransientModel):
_name = 'sale.confirm'
_description = 'Wizard to confirm a sale order'
sale_id = fields.Many2one(
'sale.order', string='Sale Order', readonly=True)
client_order_ref = fields.Char(string='Customer PO Number')
payment_term_id = fields.Many2one(
'account.payment.term', string='Payment Terms')
partner_invoice_id = fields.Many2one(
'res.partner', 'Invoice Address', required=True)
show_partner_invoice_id = fields.Many2one(
related='partner_invoice_id', readonly=True,
string='Detailed Invoice Address')
partner_shipping_id = fields.Many2one(
'res.partner', 'Delivery Address', required=True)
show_partner_shipping_id = fields.Many2one(
related='partner_shipping_id', readonly=True,
string='Detailed Delivery Address')
@api.model
def _prepare_default_get(self, order):
default = {
'sale_id': order.id,
'client_order_ref': order.client_order_ref,
'payment_term_id': order.payment_term_id.id or False,
'partner_invoice_id': order.partner_invoice_id.id,
'partner_shipping_id': order.partner_shipping_id.id,
}
return default
@api.model
def default_get(self, fields):
res = super(SaleConfirm, self).default_get(fields)
assert self._context.get('active_model') == 'sale.order',\
'active_model should be sale.order'
order = self.env['sale.order'].browse(self._context.get('active_id'))
default = self._prepare_default_get(order)
res.update(default)
return res
@api.multi
def _prepare_update_so(self):
self.ensure_one()
return {
'client_order_ref': self.client_order_ref,
'payment_term_id': self.payment_term_id.id or False,
'partner_invoice_id': self.partner_invoice_id.id,
'partner_shipping_id': self.partner_shipping_id.id,
}
@api.multi
def confirm(self):
self.ensure_one()
vals = self._prepare_update_so()
self.sale_id.write(vals)
# confirm sale order
self.sale_id.action_confirm()
return True

View File

@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
© 2017 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>
<record id="sale_confirm_form" model="ir.ui.view">
<field name="name">sale.confirm.form</field>
<field name="model">sale.confirm</field>
<field name="arch" type="xml">
<form string="Confirm Order">
<div><p>At this stage, you have received the Purchase Order from the customer and you are about to convert the related quotation to an order.</p></div>
<group name="main">
<field name="sale_id"/>
<field name="client_order_ref"/>
<field name="partner_invoice_id" context="{'default_type': 'invoice'}"
groups="sale.group_delivery_invoice_address"/>
<!-- partner_invoice_id can't show the full address because
we are in edit mode -->
<field name="show_partner_invoice_id" options="{'always_reload': True}"
context="{'show_address': 1}"
groups="sale.group_delivery_invoice_address"/>
<field name="partner_shipping_id"
context="{'default_type': 'delivery'}"
groups="sale.group_delivery_invoice_address"/>
<field name="show_partner_shipping_id" options="{'always_reload': True}"
context="{'show_address': 1}"
groups="sale.group_delivery_invoice_address"/>
<field name="payment_term_id"/>
</group>
<footer>
<button type="object" name="confirm"
string="Confirm Sale" class="btn-primary"/>
or
<button special="cancel" string="Annuler" class="btn-default"/>
</footer>
</form>
</field>
</record>
<record id="sale_confirm_action" model="ir.actions.act_window">
<field name="name">Confirm Order</field>
<field name="res_model">sale.confirm</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</odoo>