-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
1 parent
95a0a0c
commit 912b83f
Showing
13 changed files
with
172 additions
and
15 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
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
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,19 @@ | ||
# Copyright (C) 2017 Open Source Integrators | ||
# Copyright (C) 2019 Brian McMaster | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
openupgrade.logged_query( | ||
env.cr, | ||
""" | ||
UPDATE account_move_line aml | ||
SET is_1099 = v.is_1099, | ||
type_1099_id = v.type_1099_id, | ||
box_1099_misc_id = v.box_1099_misc_id | ||
FROM res_partner v | ||
WHERE aml.partner_id = v.id | ||
""", | ||
) |
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
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,63 @@ | ||
# Copyright (C) 2021 Open Source Integrators | ||
# Copyright (C) 2019 Brian McMaster | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
@api.onchange("partner_id") | ||
def _onchange_partner_id(self): | ||
"""If lines are already added and user change the partner then | ||
set 1099 information from the new partner""" | ||
result = super(AccountMove, self)._onchange_partner_id() | ||
self.invoice_line_ids.is_1099 = self.partner_id.is_1099 | ||
self.invoice_line_ids.type_1099_id = self.partner_id.type_1099_id.id | ||
self.invoice_line_ids.box_1099_misc_id = self.partner_id.box_1099_misc_id.id | ||
return result | ||
|
||
|
||
class AccountMoveLine(models.Model): | ||
_inherit = "account.move.line" | ||
|
||
is_1099 = fields.Boolean("Is a 1099?", compute="_compute_is_1099", store=True) | ||
type_1099_id = fields.Many2one("type.1099", string="1099 Type") | ||
box_1099_misc_id = fields.Many2one("box.1099.misc", string="1099-MISC Box") | ||
legal_id_number = fields.Char( | ||
related="partner_id.legal_id_number", string="Legal ID" | ||
) | ||
|
||
@api.depends("product_id") | ||
def _compute_is_1099(self): | ||
for record in self: | ||
record.is_1099 = ( | ||
record.move_id.partner_id.is_1099 | ||
and record.product_id.type == "service" | ||
) | ||
|
||
@api.model | ||
def default_get(self, default_fields): | ||
# OVERRIDE | ||
# Update is_1099, type_1099_id and box_1099_misc_id from default partner | ||
values = super(AccountMoveLine, self).default_get(default_fields) | ||
if values.get("partner_id"): | ||
partner = self.env["res.partner"].browse(values.get("partner_id")) | ||
values.update( | ||
{ | ||
"is_1099": partner.is_1099, | ||
"type_1099_id": partner.type_1099_id.id, | ||
"box_1099_misc_id": partner.box_1099_misc_id.id, | ||
} | ||
) | ||
return values | ||
|
||
@api.onchange("is_1099", "type_1099_id") | ||
def onchange_is_1099(self): | ||
if not self.is_1099: | ||
self.type_1099_id = False | ||
self.box_1099_misc_id = False | ||
type_1099_id = self.env.ref("l10n_us_form_1099.1099_type_misc") | ||
if self.type_1099_id != type_1099_id: | ||
self.box_1099_misc_id = False |
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
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
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
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
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
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
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
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,58 @@ | ||
<odoo> | ||
<!-- Copyright (C) 2021 Open Source Integrators Copyright (C) 2019 Brian | ||
McMaster License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
|
||
<record id="account_move_view_form_l10n_us_1099" model="ir.ui.view"> | ||
<field name="name">account_move_line_view_form</field> | ||
<field name="model">account.move</field> | ||
<field name="inherit_id" ref="account.view_move_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath | ||
expr="//field[@name='invoice_line_ids']//field[@name='account_id']" | ||
position="after" | ||
> | ||
<field | ||
name="is_1099" | ||
attrs="{'column_invisible' : [('parent.move_type', '!=', 'in_invoice')]}" | ||
/> | ||
<field | ||
name="type_1099_id" | ||
options="{'no_create': 1, 'no_open':1}" | ||
attrs="{'readonly': [('is_1099', '=', False)], 'column_invisible' : [('parent.move_type', '!=', 'in_invoice')]}" | ||
/> | ||
<field | ||
name="box_1099_misc_id" | ||
options="{'no_create': 1, 'no_open':1}" | ||
attrs="{'readonly': ['|',('is_1099', '=', False),('type_1099_id', '!=', %(l10n_us_form_1099.1099_type_misc)d)], | ||
'column_invisible' : [('parent.move_type', '!=', 'in_invoice')]}" | ||
/> | ||
<field | ||
name="legal_id_number" | ||
attrs="{'column_invisible' : [('parent.move_type', '!=', 'in_invoice')]}" | ||
/> | ||
</xpath> | ||
|
||
<xpath | ||
expr="//field[@name='line_ids']//field[@name='account_id']" | ||
position="after" | ||
> | ||
<field name="is_1099" invisible="1" /> | ||
<field | ||
name="type_1099_id" | ||
options="{'no_create': 1, 'no_open':1}" | ||
attrs="{'readonly': [('is_1099', '=', False)]}" | ||
invisible="1" | ||
/> | ||
<field | ||
name="box_1099_misc_id" | ||
options="{'no_create': 1, 'no_open':1}" | ||
invisible="1" | ||
attrs="{'readonly': ['|', ('is_1099', '=', False),('type_1099_id', '!=', %(l10n_us_form_1099.1099_type_misc)d)]}" | ||
/> | ||
<field name="legal_id_number" invisible="1" /> | ||
</xpath> | ||
|
||
</field> | ||
</record> | ||
|
||
</odoo> |