sale_usability: Add sale_ids and sale_count on account.invoice
Show sale_line_ids on invoice line form view
This commit is contained in:
@@ -30,6 +30,7 @@ This module has been written by Alexis de Lattre from Akretion
|
|||||||
'sale_view.xml',
|
'sale_view.xml',
|
||||||
'sale_report_view.xml',
|
'sale_report_view.xml',
|
||||||
'product_view.xml',
|
'product_view.xml',
|
||||||
|
'account_invoice_view.xml',
|
||||||
],
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,46 @@
|
|||||||
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
# @author Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import models
|
from odoo import api, fields, models
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
class AccountInvoice(models.Model):
|
class AccountInvoice(models.Model):
|
||||||
_inherit = 'account.invoice'
|
_inherit = 'account.invoice'
|
||||||
|
|
||||||
|
# sale_ids is kind of the symetric field of invoice_ids on sale.order
|
||||||
|
sale_ids = fields.Many2many(
|
||||||
|
'sale.order', string='Sale Orders', compute="_compute_sale_ids",
|
||||||
|
readonly=True, copy=False)
|
||||||
|
sale_count = fields.Integer(
|
||||||
|
string='Sale Order Count', compute='_compute_sale_ids', readonly=True)
|
||||||
|
|
||||||
|
@api.depends('invoice_line_ids.sale_line_ids')
|
||||||
|
def _compute_sale_ids(self):
|
||||||
|
for invoice in self:
|
||||||
|
if invoice.type == 'out_invoice':
|
||||||
|
sales = invoice.invoice_line_ids.mapped('sale_line_ids').\
|
||||||
|
mapped('order_id')
|
||||||
|
invoice.sale_ids = sales.ids
|
||||||
|
invoice.sale_count = len(sales.ids)
|
||||||
|
else:
|
||||||
|
invoice.sale_ids = []
|
||||||
|
invoice.sale_count = 0
|
||||||
|
|
||||||
|
def show_sale_orders(self):
|
||||||
|
self.ensure_one()
|
||||||
|
action = self.env.ref('sale.action_orders').read()[0]
|
||||||
|
sales = self.sale_ids
|
||||||
|
if len(sales) > 1:
|
||||||
|
action['domain'] = [('id', 'in', sales.ids)]
|
||||||
|
else:
|
||||||
|
action.update({
|
||||||
|
'res_id': sales.id,
|
||||||
|
'view_mode': 'form,tree,kanban,calendar,pivot,graph,activity',
|
||||||
|
'views': False,
|
||||||
|
})
|
||||||
|
return action
|
||||||
|
|
||||||
def py3o_lines_layout_groupby_order(self, subtotal=True):
|
def py3o_lines_layout_groupby_order(self, subtotal=True):
|
||||||
# This method is an alternative to the method py3o_lines_layout()
|
# This method is an alternative to the method py3o_lines_layout()
|
||||||
# defined above: you just have to change the call in the invoice
|
# defined above: you just have to change the call in the invoice
|
||||||
|
|||||||
39
sale_usability/account_invoice_view.xml
Normal file
39
sale_usability/account_invoice_view.xml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2019 Akretion France (http://www.akretion.com/)
|
||||||
|
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
-->
|
||||||
|
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
|
||||||
|
<record id="account_invoice_form" model="ir.ui.view">
|
||||||
|
<field name="name">sale_usability.customer.invoice.form</field>
|
||||||
|
<field name="model">account.invoice</field>
|
||||||
|
<field name="inherit_id" ref="sale.account_invoice_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<div name="button_box" position="inside">
|
||||||
|
<button name="show_sale_orders"
|
||||||
|
type="object"
|
||||||
|
class="oe_stat_button"
|
||||||
|
icon="fa-pencil-square-o"
|
||||||
|
attrs="{'invisible': [('sale_count', '=', 0)]}">
|
||||||
|
<field name="sale_count" widget="statinfo" string="Sale Orders"/>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="account_invoice_line_form" model="ir.ui.view">
|
||||||
|
<field name="name">sale_usability.invoice.line.form</field>
|
||||||
|
<field name="model">account.invoice.line</field>
|
||||||
|
<field name="inherit_id" ref="sale.account_invoice_line_form"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@groups='analytic.group_analytic_tags']" position="after">
|
||||||
|
<field name="sale_line_ids" widget="many2many_tags" attrs="{'invisible': [('invoice_type', 'in', ('in_invoice', 'in_refund'))]}"/>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
from odoo import models, fields, api
|
from odoo import models, fields, api
|
||||||
from odoo.tools import float_is_zero
|
from odoo.tools import float_is_zero
|
||||||
from collections import OrderedDict
|
|
||||||
|
|
||||||
|
|
||||||
class SaleOrder(models.Model):
|
class SaleOrder(models.Model):
|
||||||
|
|||||||
Reference in New Issue
Block a user