Skip to content

Commit

Permalink
[ADD] sale_order_partner_invoice_period: added last requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
DantePereyra committed Nov 26, 2024
1 parent 6d1e51f commit 27748aa
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 14 deletions.
3 changes: 2 additions & 1 deletion sale_order_partner_invoice_period/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
],
"data": [
"views/res_partner_view.xml",
"views/sale_order_view.xml"
"views/sale_order_view.xml",
"views/res_config_settings.xml"
],
'installable': True,
}
1 change: 1 addition & 0 deletions sale_order_partner_invoice_period/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import res_config_settings
from . import res_partner
from . import sale_order
20 changes: 20 additions & 0 deletions sale_order_partner_invoice_period/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# © 2024 Solvos Consultoría Informática (<http://www.solvos.es>)
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html
from odoo import fields, models
from .res_partner import INVOICE_PERIOD_SELECTION

class ResCompany(models.Model):
_inherit = "res.company"

invoice_period_default = fields.Selection(INVOICE_PERIOD_SELECTION)

class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

invoice_period_default = fields.Selection(
selection=INVOICE_PERIOD_SELECTION,
related='company_id.invoice_period_default',
help="Select default invoice period for new companys",
readonly=False
)

13 changes: 11 additions & 2 deletions sale_order_partner_invoice_period/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# © 2024 Solvos Consultoría Informática (<http://www.solvos.es>)
# License LGPL-3 - See http://www.gnu.org/licenses/lgpl-3.0.html
from odoo import models, fields
from odoo import models, fields, api

INVOICE_PERIOD_SELECTION = [
('daily','Daily'),
Expand All @@ -11,8 +11,17 @@
('yearly','Yearly')
]


class ResPartner(models.Model):
_inherit = "res.partner"

invoice_period = fields.Selection(INVOICE_PERIOD_SELECTION)

@api.model
def create(self, vals):
partner = super(ResPartner, self).create(vals)
if not partner.invoice_period:
if partner.is_company:
partner.invoice_period = self.env.company.invoice_period_default
else:
partner.invoice_period = partner.parent_id.invoice_period
return partner
17 changes: 6 additions & 11 deletions sale_order_partner_invoice_period/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@ class SaleOrder(models.Model):
@api.depends('partner_invoice_id.invoice_period', 'partner_invoice_id.parent_id.invoice_period')
def _compute_partner_invoice_period(self):
for order in self:
if order.partner_invoice_id:
if order.partner_invoice_id.invoice_period:
order.partner_invoice_period = order.partner_invoice_id.invoice_period
elif (
order.partner_invoice_id.parent_id
and order.partner_invoice_id.parent_id.invoice_period):
order.partner_invoice_period = order.partner_invoice_id.parent_id.invoice_period
else:
order.partner_invoice_period = False
else:
order.partner_invoice_period = False
order.partner_invoice_period = (
order.partner_invoice_id.invoice_period
or
order.partner_invoice_id.parent_id.invoice_period
)

20 changes: 20 additions & 0 deletions sale_order_partner_invoice_period/views/res_config_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">
res.config.settings.view.form.inherit.sale (in sale_order_partner_invoice_period)
</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="20"/>
<field name="inherit_id" ref="sale.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//setting[@id='automatic_invoicing']" position="after">
<setting id="default_invoice_period" help="Select default invoice period for new companys">
<field name="invoice_period_default"/>
</setting>
</xpath>
</field>
</record>

</odoo>

0 comments on commit 27748aa

Please sign in to comment.