Several improvements in order to improve user interface are done here. [IMP] purchase: Prevent create PO&RFQ in calendar It was possible to create PO's and RFQ's from the calendar view. The Product Owner wanted to prevent the users from doing so. [IMP] purchase: Add tooltip to Receipt Date [FIX] purchase: Align report & stat button data on product form The use of Last 365 days time_range in the purchase analysis was automatically excluding today's purchases wich was confusing users as the stat button info was taking those into account. Different behaviours were implemented for product template and product product in the filters that were used which makes no sense. Use of context_today() instead of datetime.now() in order to take the user's timezone into account. [IMP] purchase: Use relevant dates for RFQ's and PO's in calendar view The date used in order to display RFQs and POs in the calendar was date_planned which is not mandatory and so not always filled. It has been decided to use the order_date for the RFQ's and date_approve for PO's. [IMP] purchase_requisition: Making Agreement selection type more explicit [IMP] purchase: Show UOM menu only if installed [IMP] purchase: Add product variant in settings [IMP] purchase: Remove Favorites predefined filters [IMP] purchase: Rephrase PO action helper [IMP] purchase: Allow open/edit Agreement Type [IMP] purchase: Rephrase RFQ action helper [IMP] purchase: Remove PO's and RFQ's name from fields in calendar The Product Owner originally wanted to have a link on the PO name field that was shown in the calendat popover. As the Edit button already allows to edit the PO's or RFQ's from the popover it was decided to simply remove the field (as it was already displayed at the top of the popover) [IMP] purchase: Open the right view when click on Reporting top menu Task ID #2196688 Closes #47810 Related: odoo/enterprise#9294 Related: odoo/upgrade#961 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
98 lines
4.4 KiB
Python
98 lines
4.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from datetime import timedelta
|
|
from odoo import api, fields, models, _
|
|
from odoo.addons.base.models.res_partner import WARNING_MESSAGE, WARNING_HELP
|
|
from odoo.tools.float_utils import float_round
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
|
|
class ProductTemplate(models.Model):
|
|
_name = 'product.template'
|
|
_inherit = 'product.template'
|
|
|
|
property_account_creditor_price_difference = fields.Many2one(
|
|
'account.account', string="Price Difference Account", company_dependent=True,
|
|
help="This account is used in automated inventory valuation to "\
|
|
"record the price difference between a purchase order and its related vendor bill when validating this vendor bill.")
|
|
purchased_product_qty = fields.Float(compute='_compute_purchased_product_qty', string='Purchased')
|
|
purchase_method = fields.Selection([
|
|
('purchase', 'On ordered quantities'),
|
|
('receive', 'On received quantities'),
|
|
], string="Control Policy", help="On ordered quantities: Control bills based on ordered quantities.\n"
|
|
"On received quantities: Control bills based on received quantities.", default="receive")
|
|
purchase_line_warn = fields.Selection(WARNING_MESSAGE, 'Purchase Order Line', help=WARNING_HELP, required=True, default="no-message")
|
|
purchase_line_warn_msg = fields.Text('Message for Purchase Order Line')
|
|
|
|
def _compute_purchased_product_qty(self):
|
|
for template in self:
|
|
template.purchased_product_qty = float_round(sum([p.purchased_product_qty for p in template.product_variant_ids]), precision_rounding=template.uom_id.rounding)
|
|
|
|
@api.model
|
|
def get_import_templates(self):
|
|
res = super(ProductTemplate, self).get_import_templates()
|
|
if self.env.context.get('purchase_product_template'):
|
|
return [{
|
|
'label': _('Import Template for Products'),
|
|
'template': '/purchase/static/xls/product_purchase.xls'
|
|
}]
|
|
return res
|
|
|
|
def action_view_po(self):
|
|
action = self.env.ref('purchase.action_purchase_order_report_all').read()[0]
|
|
action['domain'] = ['&', ('state', 'in', ['purchase', 'done']), ('product_tmpl_id', 'in', self.ids)]
|
|
action['context'] = {
|
|
'graph_measure': 'qty_ordered',
|
|
'search_default_later_than_a_year_ago': True
|
|
}
|
|
return action
|
|
|
|
|
|
class ProductProduct(models.Model):
|
|
_name = 'product.product'
|
|
_inherit = 'product.product'
|
|
|
|
purchased_product_qty = fields.Float(compute='_compute_purchased_product_qty', string='Purchased')
|
|
|
|
def _compute_purchased_product_qty(self):
|
|
date_from = fields.Datetime.to_string(fields.Date.context_today(self) - relativedelta(years=1))
|
|
domain = [
|
|
('order_id.state', 'in', ['purchase', 'done']),
|
|
('product_id', 'in', self.ids),
|
|
('order_id.date_approve', '>=', date_from)
|
|
]
|
|
order_lines = self.env['purchase.order.line'].read_group(domain, ['product_id', 'product_uom_qty'], ['product_id'])
|
|
purchased_data = dict([(data['product_id'][0], data['product_uom_qty']) for data in order_lines])
|
|
for product in self:
|
|
if not product.id:
|
|
product.purchased_product_qty = 0.0
|
|
continue
|
|
product.purchased_product_qty = float_round(purchased_data.get(product.id, 0), precision_rounding=product.uom_id.rounding)
|
|
|
|
def action_view_po(self):
|
|
action = self.env.ref('purchase.action_purchase_order_report_all').read()[0]
|
|
action['domain'] = ['&', ('state', 'in', ['purchase', 'done']), ('product_id', 'in', self.ids)]
|
|
action['context'] = {
|
|
'graph_measure': 'qty_ordered',
|
|
'search_default_later_than_a_year_ago': True
|
|
}
|
|
return action
|
|
|
|
|
|
class ProductCategory(models.Model):
|
|
_inherit = "product.category"
|
|
|
|
property_account_creditor_price_difference_categ = fields.Many2one(
|
|
'account.account', string="Price Difference Account",
|
|
company_dependent=True,
|
|
help="This account will be used to value price difference between purchase price and accounting cost.")
|
|
|
|
|
|
class ProductSupplierinfo(models.Model):
|
|
_inherit = "product.supplierinfo"
|
|
|
|
@api.onchange('name')
|
|
def _onchange_name(self):
|
|
self.currency_id = self.name.property_purchase_currency_id.id or self.env.company.currency_id.id
|