Compare commits

...

4 Commits

Author SHA1 Message Date
Raphaël Valyi
ce2255623d [ADD] web_tab_title 2021-10-26 22:06:48 -03:00
Kevin.roche
2854d4fdda [IMP] sale_usability: access to sale orders from invoice view 2021-10-21 22:51:08 +02:00
Alexis de Lattre
6c51a92acc account_usability: delete invoice PDF attachment when putting a customer invoice/refund back to draft
This feature was native up to v12, but was forgotten in the invoice/move merge of v13
2021-10-21 22:48:51 +02:00
Alexis de Lattre
f3910ab528 account_usability: remove field default_move_line_name which we don't use any more 2021-10-20 23:29:04 +02:00
7 changed files with 141 additions and 12 deletions

View File

@@ -11,8 +11,6 @@ from odoo.osv import expression
class AccountMove(models.Model): class AccountMove(models.Model):
_inherit = 'account.move' _inherit = 'account.move'
default_move_line_name = fields.Char(
string='Default Label', states={'posted': [('readonly', True)]})
# By default, we can still modify "ref" when account move is posted # By default, we can still modify "ref" when account move is posted
# which seems a bit lazy for me... # which seems a bit lazy for me...
ref = fields.Char(states={'posted': [('readonly', True)]}) ref = fields.Char(states={'posted': [('readonly', True)]})
@@ -180,6 +178,35 @@ class AccountMove(models.Model):
]) ])
move.suitable_journal_ids = self.env['account.journal'].search(domain) move.suitable_journal_ids = self.env['account.journal'].search(domain)
def button_draft(self):
super().button_draft()
# Delete attached pdf invoice
try:
report_invoice = self.env['ir.actions.report']._get_report_from_name('account.report_invoice')
except IndexError:
report_invoice = False
if report_invoice and report_invoice.attachment:
for move in self.filtered(lambda x: x.move_type in ('out_invoice', 'out_refund')):
# The pb is that the filename is dynamic and related to move.state
# in v12, the feature was native and they used that kind of code:
# with invoice.env.do_in_draft():
# invoice.number, invoice.state = invoice.move_name, 'open'
# attachment = self.env.ref('account.account_invoices').retrieve_attachment(invoice)
# But do_in_draft() doesn't exists in v14
# If you know how we could do that, please update the code below
attachment = self.env['ir.attachment'].search([
('name', '=', self._get_invoice_attachment_name()),
('res_id', '=', move.id),
('res_model', '=', self._name),
('type', '=', 'binary'),
], limit=1)
if attachment:
attachment.unlink()
def _get_invoice_attachment_name(self):
self.ensure_one()
return '%s.pdf' % (self.name and self.name.replace('/', '_') or 'INV')
class AccountMoveLine(models.Model): class AccountMoveLine(models.Model):
_inherit = 'account.move.line' _inherit = 'account.move.line'

View File

@@ -7,24 +7,24 @@
<odoo> <odoo>
<!--
<record id="account_invoice_form" model="ir.ui.view"> <record id="account_invoice_form" model="ir.ui.view">
<field name="name">sale_usability.customer.invoice.form</field> <field name="name">sale_usability.customer.invoice.form</field>
<field name="model">account.invoice</field> <field name="model">account.move</field>
<field name="inherit_id" ref="sale.account_invoice_form"/> <field name="inherit_id" ref="sale.account_invoice_form" />
<field name="groups_id" eval="[(4, ref('sales_team.group_sale_manager'))]" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<div name="button_box" position="inside"> <div name="button_box" position="inside">
<button name="show_sale_orders" <button
type="object" name="show_sale_orders"
class="oe_stat_button" type="object"
icon="fa-pencil-square-o" class="oe_stat_button"
attrs="{'invisible': [('sale_count', '=', 0)]}"> icon="fa-pencil-square-o"
<field name="sale_count" widget="statinfo" string="Sale Orders"/> attrs="{'invisible': [('sale_count', '=', 0)]}">
<field name="sale_count" widget="statinfo" string="Sale Orders" />
</button> </button>
</div> </div>
</field> </field>
</record> </record>
-->
<record id="view_move_form" model="ir.ui.view"> <record id="view_move_form" model="ir.ui.view">
<field name="name">sale_usability.account.move.form</field> <field name="name">sale_usability.account.move.form</field>

View File

View File

@@ -0,0 +1,23 @@
# Copyright 2021 Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Web Tab Title',
'description': """
Automatically set tab document.title when empty.
Important limitation: the tab will get its title only once you browse it.
""",
'version': '14.0.1.0.0',
'license': 'AGPL-3',
'author': 'Akretion',
'website': 'akretion.com',
'depends': [
'web',
],
'data': [
],
'demo': [
],
"data": ["views/web_tab_title.xml"],
"maintainers": ["rvalyi"],
}

View File

@@ -0,0 +1,29 @@
/* global vis, py */
odoo.define("web_tab_title.AbstractWebClient", function (require) {
"use strict";
var AbstractWebClient = require('web.AbstractWebClient');
var TabTitleAbstractWebClient = AbstractWebClient.include({
_title_changed: function () {
// like the original except we change the title
// only when it's different from "Odoo" to avoid
// resetting the tab title when switching tabs.
var parts = _.sortBy(_.keys(this.get("title_part")), function (x) { return x; });
var tmp = "";
_.each(parts, function (part) {
var str = this.get("title_part")[part];
if (str) {
tmp = tmp ? tmp + " - " + str : str;
}
}, this);
if (tmp != "Odoo") {
document.title = tmp;
}
},
});
return TabTitleAbstractWebClient;
});

View File

@@ -0,0 +1,31 @@
/* global vis, py */
odoo.define("web_tab_title.FormController", function (require) {
"use strict";
var FormController = require('web.FormController');
var TabTitleController = FormController.include({
on_attach_callback: function () {
this._super.apply(this, arguments);
if (document.title == "Odoo") {
var form_name_elem = $("div.oe_title>h1");
if (form_name_elem.length == 0) {
form_name_elem = $('span.o_field_char[name="name"]')
}
var title = form_name_elem.text();
if (title !== '') {
// alternatively we could access the record
// in views/basic/basic_model.js
// but we would also we miss the model name
document.title = title + " - Odoo";
}
}
},
});
return TabTitleController;
});

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template
id="assets_backend"
name="web_timeline assets"
inherit_id="web.assets_backend"
>
<xpath expr="." position="inside">
<script
type="text/javascript"
src="/web_tab_title/static/src/js/form_controller.js"
/>
<script
type="text/javascript"
src="/web_tab_title/static/src/js/abstract_web_client.js"
/>
</xpath>
</template>
</odoo>