diff --git a/__init__.py b/__init__.py index d548d15..83a8b40 100644 --- a/__init__.py +++ b/__init__.py @@ -1,4 +1,5 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import models -from . import controllers \ No newline at end of file +from . import controllers +from . import wizard \ No newline at end of file diff --git a/__manifest__.py b/__manifest__.py index f846dce..c3905e2 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -19,6 +19,8 @@ "views/vracoop_sale_retrait_views.xml", "views/vracoop_templates.xml", "views/sale_order.xml", - "views/delivery_views.xml" + "views/delivery_views.xml", + "views/account_invoice_views.xml", + "report/account_invoice_template.xml" ] } diff --git a/models/__init__.py b/models/__init__.py index bf52ecf..52f7c5c 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -5,4 +5,5 @@ from . import vracoop_point_retrait from . import vracoop_retrait_time from . import vracoop_retrait_suivi from . import sale_order +from . import account_invoice from . import delivery \ No newline at end of file diff --git a/models/account_invoice.py b/models/account_invoice.py new file mode 100644 index 0000000..c74e9ff --- /dev/null +++ b/models/account_invoice.py @@ -0,0 +1,48 @@ +# Copyright 2021 Le Filament () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models +from datetime import datetime + + +class AccountInvoice(models.Model): + _inherit = 'account.invoice' + + # ------------------------------------------------------ + # Fields declaration + # ------------------------------------------------------ + vracoop_point_retrait_id = fields.Many2one( + comodel_name='vracoop.point.retrait', + string="Point retrait") + day_retrait = fields.Date("Jour du retrait") + hour_retrait = fields.Float("Heure du retrait") + carrier_point_retrait = fields.Boolean( + string='Est un point retrait') + + # ------------------------------------------------------ + # SQL Constraints + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Default methods + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Computed fields / Search Fields + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Onchange / Constraints + # ------------------------------------------------------ + + # ------------------------------------------------------ + # CRUD methods (ORM overrides) + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Actions + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Business methods + # ------------------------------------------------------ diff --git a/models/sale_order.py b/models/sale_order.py index 7a49fc2..5c40a1f 100644 --- a/models/sale_order.py +++ b/models/sale_order.py @@ -1,7 +1,7 @@ # © 2019 Le Filament () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import models, fields +from odoo import models, fields, api from datetime import datetime class SaleOrder(models.Model): @@ -42,4 +42,16 @@ class SaleOrder(models.Model): 'day_retrait': day_retrait, 'vracoop_point_retrait_id': retrait.id}) - return True \ No newline at end of file + return True + + @api.multi + def _prepare_invoice(self): + self.ensure_one() + res = super(SaleOrder, self)._prepare_invoice() + res.update({ + 'vracoop_point_retrait_id': self.vracoop_point_retrait_id.id, + 'day_retrait': self.day_retrait, + 'hour_retrait': self.hour_retrait, + 'carrier_point_retrait': self.carrier_point_retrait + }) + return res \ No newline at end of file diff --git a/models/vracoop_point_retrait.py b/models/vracoop_point_retrait.py index 1c01c69..b6d3d5c 100644 --- a/models/vracoop_point_retrait.py +++ b/models/vracoop_point_retrait.py @@ -2,14 +2,8 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import models, fields, api -import pytz -# import dateutil.rrule as rrule -# from datetime import date -from dateutil.relativedelta import * -from dateutil.easter import * -from dateutil.rrule import rrule, DAILY, MINUTELY, rruleset -from dateutil.parser import * -# from datetime import * +from dateutil.rrule import rrule, DAILY, MINUTELY +from dateutil.relativedelta import relativedelta from datetime import datetime, timedelta from pytz import timezone @@ -67,6 +61,8 @@ class VracoopPointRetrait(models.Model): "Nombre de retrait max par tranche horaire") nb_day_available = fields.Integer( "Nombre de jours pour commande", default=7) + nb_hours_preparation = fields.Float( + "Nombre d'heures de préparation", default=0.0) @api.multi def slot_calculate(self): @@ -103,10 +99,11 @@ class VracoopPointRetrait(models.Model): # Liste des jours où je peux récupérer la commande # en fonction nombre de jour dispo sur la fiche du point retrait + first_day = datetime.today() + relativedelta(hours=rec.nb_hours_preparation) list_week = list(rrule( DAILY, count=count_day, - dtstart=datetime.today())) + dtstart=first_day)) for week in list_week: # On exclut les jours où la journée @@ -172,7 +169,7 @@ class VracoopPointRetrait(models.Model): # Heure disponible pour un retrait # en fonction du temps de préparation today_hour_available = today_datetime + timedelta( - hours=corresponding_line.preparation_time) + hours=(corresponding_line.preparation_time + rec.nb_hours_preparation)) # Boucle pour les créneaux du matin for slot_elem in list_slot_per_day_morning: @@ -194,7 +191,8 @@ class VracoopPointRetrait(models.Model): last_slot = slot_elem_last.strftime("%H:%M") # Si le jour est égal à la date du jour - if slot_elem.date() == today_datetime.date(): + day_first = today_datetime.date() + relativedelta(hours=rec.nb_hours_preparation) + if slot_elem.date() == day_first: if (slot_elem_last > last_morning_hour_week): if (today_hour_available > last_morning_hour_week): continue diff --git a/report/account_invoice_template.xml b/report/account_invoice_template.xml new file mode 100644 index 0000000..3d9173d --- /dev/null +++ b/report/account_invoice_template.xml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/views/account_invoice_views.xml b/views/account_invoice_views.xml new file mode 100644 index 0000000..49965d2 --- /dev/null +++ b/views/account_invoice_views.xml @@ -0,0 +1,22 @@ + + + + + + account.invoice.form.view.with_retrait + account.invoice + + + + + + + + + > + + + + + + \ No newline at end of file diff --git a/views/vracoop_retrait_views.xml b/views/vracoop_retrait_views.xml index 11b74f1..564826c 100644 --- a/views/vracoop_retrait_views.xml +++ b/views/vracoop_retrait_views.xml @@ -98,6 +98,7 @@ + diff --git a/wizard/__init__.py b/wizard/__init__.py new file mode 100644 index 0000000..91dfca5 --- /dev/null +++ b/wizard/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2020 Le Filament () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import sale_make_invoice_advance diff --git a/wizard/__pycache__/__init__.cpython-37.pyc b/wizard/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..f711a54 Binary files /dev/null and b/wizard/__pycache__/__init__.cpython-37.pyc differ diff --git a/wizard/__pycache__/sale_make_invoice_advance.cpython-37.pyc b/wizard/__pycache__/sale_make_invoice_advance.cpython-37.pyc new file mode 100644 index 0000000..d79faca Binary files /dev/null and b/wizard/__pycache__/sale_make_invoice_advance.cpython-37.pyc differ diff --git a/wizard/sale_make_invoice_advance.py b/wizard/sale_make_invoice_advance.py new file mode 100644 index 0000000..acf6251 --- /dev/null +++ b/wizard/sale_make_invoice_advance.py @@ -0,0 +1,50 @@ +# Copyright 2021 Le Filament () +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from odoo import api, fields, models, _ + + +class SaleAdvancePaymentInv(models.TransientModel): + _inherit = "sale.advance.payment.inv" + + # ------------------------------------------------------ + # Fields declaration + # ------------------------------------------------------ + @api.multi + def _create_invoice(self, order, so_line, amount): + inv = super(SaleAdvancePaymentInv, self)._create_invoice(order, so_line, amount) + inv.write({ + 'vracoop_point_retrait_id': order.vracoop_point_retrait_id.id, + 'day_retrait': order.day_retrait, + 'hour_retrait': order.hour_retrait, + 'carrier_point_retrait': order.carrier_point_retrait + }) + return inv + # ------------------------------------------------------ + # SQL Constraints + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Default methods + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Computed fields / Search Fields + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Onchange / Constraints + # ------------------------------------------------------ + + # ------------------------------------------------------ + # CRUD methods (ORM overrides) + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Actions + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Business methods + # ------------------------------------------------------