customer order data
This commit is contained in:
parent
ee77872c62
commit
bdea2c6c3e
|
|
@ -1,6 +1,7 @@
|
||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
from datetime import datetime
|
from datetime import date, datetime
|
||||||
|
import calendar
|
||||||
|
|
||||||
|
|
||||||
class CustomerOrder(models.Model):
|
class CustomerOrder(models.Model):
|
||||||
|
|
@ -77,11 +78,18 @@ class CustomerOrder(models.Model):
|
||||||
|
|
||||||
def _compute_dispatch_data(self):
|
def _compute_dispatch_data(self):
|
||||||
for order in self:
|
for order in self:
|
||||||
|
month = int(order.order_month)
|
||||||
|
year = fields.Date.today().year # or order.year if you have one
|
||||||
|
|
||||||
|
first_day = date(year, month, 1)
|
||||||
|
last_day = date(year, month, calendar.monthrange(year, month)[1])
|
||||||
# Get all invoice lines for this order
|
# Get all invoice lines for this order
|
||||||
invoice_lines = self.env['account.move.line'].search([
|
invoice_lines = self.env['account.move.line'].search([
|
||||||
('move_id.state', '=', 'posted'),
|
('move_id.state', '=', 'posted'),
|
||||||
('move_id.move_type', 'in', ['out_invoice', 'out_refund']),
|
('move_id.move_type', 'in', ['out_invoice', 'out_refund']),
|
||||||
('product_id', 'in', order.order_line_ids.mapped('product_id').ids)
|
('product_id', 'in', order.order_line_ids.mapped('product_id').ids),
|
||||||
|
('move_id.invoice_date', '>=', first_day),
|
||||||
|
('move_id.invoice_date', '<=', last_day),
|
||||||
])
|
])
|
||||||
|
|
||||||
if invoice_lines:
|
if invoice_lines:
|
||||||
|
|
@ -171,10 +179,22 @@ class CustomerOrder(models.Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
def _compute_production_data(self):
|
def _compute_production_data(self):
|
||||||
|
|
||||||
for order in self:
|
for order in self:
|
||||||
|
month = int(order.order_month)
|
||||||
|
year = fields.Date.today().year
|
||||||
|
|
||||||
|
first_day = date(year, month, 1)
|
||||||
|
last_day = date(year, month, calendar.monthrange(year, month)[1])
|
||||||
|
|
||||||
|
# Convert to datetime for date_start (Datetime field)
|
||||||
|
start_datetime = datetime.combine(first_day, datetime.min.time())
|
||||||
|
end_datetime = datetime.combine(last_day, datetime.max.time())
|
||||||
# Get all production orders for this customer order's products
|
# Get all production orders for this customer order's products
|
||||||
production_orders = self.env['mrp.production'].search([
|
production_orders = self.env['mrp.production'].search([
|
||||||
('product_id', 'in', order.order_line_ids.mapped('product_id').ids),
|
('product_id', 'in', order.order_line_ids.mapped('product_id').ids),
|
||||||
|
('date_start', '>=', start_datetime),
|
||||||
|
('date_start', '<=', end_datetime),
|
||||||
])
|
])
|
||||||
|
|
||||||
if production_orders:
|
if production_orders:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue