Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] account,*: Merge account.invoice & account.move #33797

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions addons/account/__manifest__.py
Expand Up @@ -32,12 +32,9 @@
'views/account_view.xml',
'views/account_report.xml',
'data/mail_template_data.xml',
'wizard/account_invoice_refund_view.xml',
'wizard/account_validate_move_view.xml',
'wizard/account_invoice_state_view.xml',
'wizard/pos_box.xml',
'views/account_end_fy.xml',
'views/account_invoice_view.xml',
'views/partner_view.xml',
'views/product_view.xml',
'views/account_analytic_view.xml',
Expand Down
18 changes: 10 additions & 8 deletions addons/account/controllers/portal.py
Expand Up @@ -11,7 +11,9 @@ class PortalAccount(CustomerPortal):

def _prepare_portal_layout_values(self):
values = super(PortalAccount, self)._prepare_portal_layout_values()
invoice_count = request.env['account.invoice'].search_count([])
invoice_count = request.env['account.move'].search_count([
('type', 'in', ('out_invoice', 'in_invoice', 'out_refund', 'in_refund', 'out_receipt', 'in_receipt')),
Copy link
Contributor

@celm1990 celm1990 Jun 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For get domain can call to function??, see #22121

DIFF c3e3770

])
values['invoice_count'] = invoice_count
return values

Expand All @@ -29,13 +31,13 @@ def _invoice_get_page_view_values(self, invoice, access_token, **kwargs):
@http.route(['/my/invoices', '/my/invoices/page/<int:page>'], type='http', auth="user", website=True)
def portal_my_invoices(self, page=1, date_begin=None, date_end=None, sortby=None, **kw):
values = self._prepare_portal_layout_values()
AccountInvoice = request.env['account.invoice']
AccountInvoice = request.env['account.move']

domain = []
domain = [('type', 'in', ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt'))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, call to common function to get domain


searchbar_sortings = {
'date': {'label': _('Invoice Date'), 'order': 'date_invoice desc'},
'duedate': {'label': _('Due Date'), 'order': 'date_due desc'},
'date': {'label': _('Invoice Date'), 'order': 'invoice_date desc'},
'duedate': {'label': _('Due Date'), 'order': 'invoice_date_due desc'},
'name': {'label': _('Reference'), 'order': 'name desc'},
'state': {'label': _('Status'), 'order': 'state'},
}
Expand All @@ -44,7 +46,7 @@ def portal_my_invoices(self, page=1, date_begin=None, date_end=None, sortby=None
sortby = 'date'
order = searchbar_sortings[sortby]['order']

archive_groups = self._get_archive_groups('account.invoice', domain)
archive_groups = self._get_archive_groups('account.move', domain)
if date_begin and date_end:
domain += [('create_date', '>', date_begin), ('create_date', '<=', date_end)]

Expand Down Expand Up @@ -77,7 +79,7 @@ def portal_my_invoices(self, page=1, date_begin=None, date_end=None, sortby=None
@http.route(['/my/invoices/<int:invoice_id>'], type='http', auth="public", website=True)
def portal_my_invoice_detail(self, invoice_id, access_token=None, report_type=None, download=False, **kw):
try:
invoice_sudo = self._document_check_access('account.invoice', invoice_id, access_token)
invoice_sudo = self._document_check_access('account.move', invoice_id, access_token)
except (AccessError, MissingError):
return request.redirect('/my')

Expand All @@ -88,7 +90,7 @@ def portal_my_invoice_detail(self, invoice_id, access_token=None, report_type=No
acquirers = values.get('acquirers')
if acquirers:
country_id = values.get('partner_id') and values.get('partner_id')[0].country_id.id
values['acq_extra_fees'] = acquirers.get_acquirer_extra_fees(invoice_sudo.residual, invoice_sudo.currency_id, country_id)
values['acq_extra_fees'] = acquirers.get_acquirer_extra_fees(invoice_sudo.amount_residual, invoice_sudo.currency_id, country_id)

return request.render("account.portal_invoice_page", values)

Expand Down
12 changes: 6 additions & 6 deletions addons/account/data/account_data.xml
Expand Up @@ -78,19 +78,19 @@
<!-- Account-related subtypes for messaging / Chatter -->
<record id="mt_invoice_validated" model="mail.message.subtype">
<field name="name">Validated</field>
<field name="res_model">account.invoice</field>
<field name="res_model">account.move</field>
<field name="default" eval="False"/>
<field name="description">Invoice validated</field>
</record>
<record id="mt_invoice_paid" model="mail.message.subtype">
<field name="name">Paid</field>
<field name="res_model">account.invoice</field>
<field name="res_model">account.move</field>
<field name="default" eval="False"/>
<field name="description">Invoice paid</field>
</record>
<record id="mt_invoice_created" model="mail.message.subtype">
<field name="name">Invoice Created</field>
<field name="res_model">account.invoice</field>
<field name="res_model">account.move</field>
<field name="default" eval="False"/>
<field name="hidden" eval="True"/>
<field name="description">Invoice Created</field>
Expand Down Expand Up @@ -175,10 +175,10 @@
</record>

<!-- Share Button in action menu -->
<record id="model_account_invoice_action_share" model="ir.actions.server">
<record id="model_account_move_action_share" model="ir.actions.server">
<field name="name">Share</field>
<field name="model_id" ref="account.model_account_invoice"/>
<field name="binding_model_id" ref="account.model_account_invoice"/>
<field name="model_id" ref="account.model_account_move"/>
<field name="binding_model_id" ref="account.model_account_move"/>
<field name="state">code</field>
<field name="code">action = records.action_share()</field>
</record>
Expand Down
16 changes: 8 additions & 8 deletions addons/account/data/mail_template_data.xml
Expand Up @@ -7,10 +7,10 @@
<!--Email template -->
<record id="email_template_edi_invoice" model="mail.template">
<field name="name">Invoice: Send by email</field>
<field name="model_id" ref="account.model_account_invoice"/>
<field name="model_id" ref="account.model_account_move"/>
<field name="email_from">${(object.user_id.email_formatted or user.email_formatted) |safe}</field>
<field name="partner_to">${object.partner_id.id}</field>
<field name="subject">${object.company_id.name} Invoice (Ref ${object.number or 'n/a'})</field>
<field name="subject">${object.company_id.name} Invoice (Ref ${object.name or 'n/a'})</field>
<field name="body_html" type="html">
<div style="margin: 0px; padding: 0px;">
<p style="margin: 0px; padding: 0px; font-size: 13px;">
Expand All @@ -22,17 +22,17 @@
% endif
<br /><br />
Here is your
% if object.number:
invoice <strong>${object.number}</strong>
% if object.name:
invoice <strong>${object.name}</strong>
% else:
invoice
%endif
% if object.origin:
(with reference: ${object.origin})
% if object.invoice_origin:
(with reference: ${object.invoice_origin})
% endif
amounting in <strong>${format_amount(object.amount_total, object.currency_id)}</strong>
from ${object.company_id.name}.
% if object.state=='paid':
% if object.invoice_payment_state == 'paid':
This invoice is already paid.
% else:
Please remit payment at your earliest convenience.
Expand All @@ -43,7 +43,7 @@
</div>
</field>
<field name="report_template" ref="account_invoices"/>
<field name="report_name">Invoice_${(object.number or '').replace('/','_')}${object.state == 'draft' and '_draft' or ''}</field>
<field name="report_name">Invoice_${(object.name or '').replace('/','_')}${object.state == 'draft' and '_draft' or ''}</field>
<field name="lang">${object.partner_id.lang}</field>
<field name="user_signature" eval="False"/>
<field name="auto_delete" eval="True"/>
Expand Down
2 changes: 1 addition & 1 deletion addons/account/data/service_cron.xml
Expand Up @@ -8,7 +8,7 @@
<field name="nextcall" eval="(DateTime.now().replace(hour=2, minute=0) + timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')" />
<field name="doall" eval="False"/>
<field name="model_id" ref="model_account_move"/>
<field name="code">model._run_post_draft_to_post()</field>
<field name="code">model._autopost_draft_entries()</field>
<field name="state">code</field>
</record>
</odoo>
3 changes: 2 additions & 1 deletion addons/account/models/__init__.py
Expand Up @@ -4,10 +4,11 @@
from . import account
from . import account_reconcile_model
from . import account_payment
from . import account_invoice
from . import account_payment_term
from . import account_bank_statement
from . import account_move
from . import account_payment_term
from . import account_bank_statement
from . import chart_template
from . import account_analytic_line
from . import account_journal_dashboard
Expand Down
71 changes: 31 additions & 40 deletions addons/account/models/account.py
Expand Up @@ -553,8 +553,6 @@ def _get_bank_statements_available_sources(self):
domain=[('deprecated', '=', False)], help="It acts as a default account for debit amount")
update_posted = fields.Boolean(string='Allow Cancelling Entries',
help="Check this box if you want to allow the cancellation the entries related to this journal or of the invoice related to this journal")
group_invoice_lines = fields.Boolean(string='Group Invoice Lines',
help="If this box is checked, the system will try to group the accounting lines when generating them from invoices.")
sequence_id = fields.Many2one('ir.sequence', string='Entry Sequence',
help="This field contains the information related to the numbering of the journal entries of this journal.", required=True, copy=False)
refund_sequence_id = fields.Many2one('ir.sequence', string='Credit Note Entry Sequence',
Expand Down Expand Up @@ -738,7 +736,7 @@ def _update_mail_alias(self, vals):
if self.alias_id:
self.alias_id.write(alias_values)
else:
self.alias_id = self.env['mail.alias'].with_context(alias_model_name='account.invoice',
self.alias_id = self.env['mail.alias'].with_context(alias_model_name='account.move',
alias_parent_model_name='account.journal').create(alias_values)

if vals.get('alias_name'):
Expand Down Expand Up @@ -1179,17 +1177,6 @@ def onchange_price_include(self):
if self.price_include:
self.include_base_amount = True

def get_grouping_key(self, invoice_tax_val):
""" Returns a string that will be used to group account.invoice.tax sharing the same properties"""
self.ensure_one()
return str(invoice_tax_val['tax_id']) + '-' + \
str(invoice_tax_val.get('tax_repartition_line_id')) + '-' + \
str(invoice_tax_val['account_id']) + '-' + \
str(invoice_tax_val['account_analytic_id']) + '-' + \
str(invoice_tax_val.get('analytic_tag_ids', [])) + '-' + \
str(invoice_tax_val.get('tax_ids') or []) + '-' + \
str(invoice_tax_val.get('tag_ids') or [])

def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None):
""" Returns the amount of a single tax. base_amount is the actual amount on which the tax is applied, which is
price_unit * quantity eventually affected by previous taxes (if tax is include_base_amount XOR price_include)
Expand All @@ -1210,7 +1197,7 @@ def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, p
else:
return quantity * self.amount

price_include = self._context['force_price_include'] if 'force_price_include' in self._context else self.price_include
price_include = self._context.get('force_price_include', self.price_include)

# base * (1 + tax_amount) = new_base
if self.amount_type == 'percent' and not price_include:
Expand Down Expand Up @@ -1254,12 +1241,15 @@ def get_tax_tags(self, is_refund, repartition_type):
return rep_lines.filtered(lambda x: x.repartition_type == repartition_type).mapped('tag_ids')

@api.multi
def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, partner=None, is_refund=False):
def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, partner=None, is_refund=False, handle_price_include=True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be good to add something in the dosctring about this parameter ; so that we understand its use directly

""" Returns all information required to apply taxes (in self + their children in case of a tax group).
We consider the sequence of the parent for group of taxes.
Eg. considering letters as taxes and alphabetic order as sequence :
[G, B([A, D, F]), E, C] will be computed as [A, D, F, C, E, G]

'handle_price_include' is used when we need to ignore all tax included in price. If False, it means the
amount passed to this method will be considered as the base of all computations.

RETURN: {
'total_excluded': 0.0, # Total without taxes
'total_included': 0.0, # Total with taxes
Expand Down Expand Up @@ -1362,28 +1352,29 @@ def recompute_base(base_amount, fixed_amount, percent_amount, division_amount):
incl_fixed_amount = incl_percent_amount = incl_division_amount = 0
# Store the tax amounts we compute while searching for the total_excluded
cached_tax_amounts = {}
for tax in reversed(taxes):
if tax.include_base_amount:
base = recompute_base(base, incl_fixed_amount, incl_percent_amount, incl_division_amount)
incl_fixed_amount = incl_percent_amount = incl_division_amount = 0
store_included_tax_total = True
if tax.price_include:
if tax.amount_type == 'percent':
incl_percent_amount += tax.amount
elif tax.amount_type == 'division':
incl_division_amount += tax.amount
elif tax.amount_type == 'fixed':
incl_fixed_amount += quantity * tax.amount
else:
# tax.amount_type == other (python)
tax_amount = tax._compute_amount(base, price_unit, quantity, product, partner)
incl_fixed_amount += tax_amount
# Avoid unecessary re-computation
cached_tax_amounts[i] = tax_amount
if store_included_tax_total:
total_included_checkpoints[i] = base
store_included_tax_total = False
i -= 1
if handle_price_include:
for tax in reversed(taxes):
if tax.include_base_amount:
base = recompute_base(base, incl_fixed_amount, incl_percent_amount, incl_division_amount)
incl_fixed_amount = incl_percent_amount = incl_division_amount = 0
store_included_tax_total = True
if tax.price_include:
if tax.amount_type == 'percent':
incl_percent_amount += tax.amount
elif tax.amount_type == 'division':
incl_division_amount += tax.amount
elif tax.amount_type == 'fixed':
incl_fixed_amount += quantity * tax.amount
else:
# tax.amount_type == other (python)
tax_amount = tax._compute_amount(base, price_unit, quantity, product, partner)
incl_fixed_amount += tax_amount
# Avoid unecessary re-computation
cached_tax_amounts[i] = tax_amount
if store_included_tax_total:
total_included_checkpoints[i] = base
store_included_tax_total = False
i -= 1

total_excluded = recompute_base(base, incl_fixed_amount, incl_percent_amount, incl_division_amount)

Expand Down Expand Up @@ -1438,8 +1429,8 @@ def recompute_base(base_amount, fixed_amount, percent_amount, division_amount):
'price_include': tax.price_include,
'tax_exigibility': tax.tax_exigibility,
'tax_repartition_line_id': repartition_line.id,
'tag_ids': [(6, False, (repartition_line.tag_ids + subsequent_tags).ids)],
'tax_ids': [(6, False, subsequent_taxes.ids)]
'tag_ids': (repartition_line.tag_ids + subsequent_tags).ids,
'tax_ids': subsequent_taxes.ids,
})

total_amount += line_amount
Expand Down