add fields 'last_order' and 'last_order_date' to res_partner (reworked)
... don't allow invoice customer with different country than order customerdevelop
parent
2e0921dd86
commit
932cbf310f
|
|
@ -82,6 +82,17 @@ class AccountInvoice(models.Model):
|
||||||
|
|
||||||
layout_category_id = fields.Many2one('sale.layout_category', related='invoice_line_ids.layout_category_id', string='Section')
|
layout_category_id = fields.Many2one('sale.layout_category', related='invoice_line_ids.layout_category_id', string='Section')
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
@api.onchange('partner_shipping_id')
|
||||||
|
def onchange_partner_shipping_id(self):
|
||||||
|
# res = super(AccountInvoice, self).onchange_partner_shipping_id()
|
||||||
|
if not self.env.user.has_group('dp_custom.group_allow_third_country_sale'):
|
||||||
|
if self.partner_invoice_id.country_id != self.partner_shipping_id.country_id:
|
||||||
|
message = _('Rechnungs- und Lieferland passen nicht zusammen: %s <-> %s!') % \
|
||||||
|
(self.partner_invoice_id.country_id.name, self.partner_shipping_id.country_id.name)
|
||||||
|
|
||||||
|
raise Warning(_(message))
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def action_invoice_open(self):
|
def action_invoice_open(self):
|
||||||
to_open_invoices = self.filtered(lambda inv: inv.state != 'open')
|
to_open_invoices = self.filtered(lambda inv: inv.state != 'open')
|
||||||
|
|
|
||||||
|
|
@ -264,8 +264,12 @@ class ProductPricelistItem(models.Model):
|
||||||
response = requests.post(portal_url + '/api/v1/update-pricelist/?secret=' + application_id,
|
response = requests.post(portal_url + '/api/v1/update-pricelist/?secret=' + application_id,
|
||||||
data=json.dumps(data))
|
data=json.dumps(data))
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
data = response.json()
|
try:
|
||||||
error_string = data.get('errors', [])
|
data = response.json()
|
||||||
|
error_string = data.get('errors', [])
|
||||||
|
except:
|
||||||
|
error_string = response.reason
|
||||||
|
|
||||||
raise ValidationError(_('Rabatt konnte nicht gesetzt werden. '
|
raise ValidationError(_('Rabatt konnte nicht gesetzt werden. '
|
||||||
'Status Code: %s, Reason: %s') % (response.status_code, error_string))
|
'Status Code: %s, Reason: %s') % (response.status_code, error_string))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,14 @@ class Partner(models.Model):
|
||||||
('portal_id_uniq', 'unique(portal_id)', 'Die Portal-ID muss eindeutig sein')
|
('portal_id_uniq', 'unique(portal_id)', 'Die Portal-ID muss eindeutig sein')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@api.depends('name', 'email')
|
||||||
|
def _compute_email_formatted(self):
|
||||||
|
for partner in self:
|
||||||
|
try:
|
||||||
|
partner.email_formatted = formataddr((partner.name or u"False", partner.email or u"False"))
|
||||||
|
except:
|
||||||
|
partner.email_formatted = partner.email
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.constrains('property_product_pricelist')
|
@api.constrains('property_product_pricelist')
|
||||||
def _check_property_product_pricelist(self):
|
def _check_property_product_pricelist(self):
|
||||||
|
|
@ -603,8 +611,9 @@ class Partner(models.Model):
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
# if not self.company_id and self.user_ids and self.env.uid != 1:
|
for partner in self:
|
||||||
# raise ValidationError(_('Dieser Datensatz gehört zu einem Benutzer und darf nur vom System-Administrator bearbeitet werden!'))
|
if not partner.company_id and partner.user_ids.id and self.env.uid != 1:
|
||||||
|
raise ValidationError(_('Dieser Datensatz gehört zu einem Benutzer und darf nur vom System-Administrator bearbeitet werden!'))
|
||||||
|
|
||||||
fields_to_check = ['ref', 'portal_id']
|
fields_to_check = ['ref', 'portal_id']
|
||||||
for field in fields_to_check:
|
for field in fields_to_check:
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from odoo import api, fields, models, _
|
from odoo import api, fields, models, _
|
||||||
from odoo.exceptions import ValidationError, UserError
|
from odoo.exceptions import ValidationError, UserError, Warning
|
||||||
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||||
from odoo.tools import float_compare
|
from odoo.tools import float_compare
|
||||||
from odoo.tools import float_is_zero
|
from odoo.tools import float_is_zero
|
||||||
|
|
@ -154,13 +154,27 @@ class SaleOrder(models.Model):
|
||||||
def _onchange_partner_invoice_id(self):
|
def _onchange_partner_invoice_id(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
# record.partner_flash = record.partner_id.partner_flash
|
# record.partner_flash = record.partner_id.partner_flash
|
||||||
|
if not self.env.user.has_group('dp_custom.group_allow_third_country_sale'):
|
||||||
|
if record.partner_invoice_id.country_id != record.partner_shipping_id.country_id:
|
||||||
|
message = _('Rechnungs- und Lieferland passen nicht zusammen: %s <-> %s!') % \
|
||||||
|
(record.partner_invoice_id.country_id, record.partner_shipping_id.country_id)
|
||||||
|
|
||||||
|
raise Warning(_(message))
|
||||||
|
|
||||||
if record.partner_invoice_id.is_retailer:
|
if record.partner_invoice_id.is_retailer:
|
||||||
record.payment_term_id = record.partner_invoice_id.property_payment_term_id
|
record.payment_term_id = record.partner_invoice_id.property_payment_term_id
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.onchange('partner_shipping_id')
|
@api.onchange('partner_shipping_id')
|
||||||
def onchange_partner_shipping_id(self):
|
def onchange_partner_shipping_id(self):
|
||||||
res = super(SaleOrder, self).onchange_partner_shipping_id()
|
res = super(SaleOrder, self).onchange_partner_shipping_id()
|
||||||
|
if not self.env.user.has_group('dp_custom.group_allow_third_country_sale'):
|
||||||
|
if self.partner_invoice_id.country_id != self.partner_shipping_id.country_id:
|
||||||
|
message = _('Rechnungs- und Lieferland passen nicht zusammen: %s <-> %s!') % \
|
||||||
|
(self.partner_invoice_id.country_id.name, self.partner_shipping_id.country_id.name)
|
||||||
|
|
||||||
|
raise Warning(_(message))
|
||||||
|
|
||||||
self.carrier_id = self.partner_shipping_id.property_delivery_carrier_id
|
self.carrier_id = self.partner_shipping_id.property_delivery_carrier_id
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
@ -505,6 +519,8 @@ class SaleOrder(models.Model):
|
||||||
current_sequence += 1
|
current_sequence += 1
|
||||||
order_line.update({'sequence': current_sequence,})
|
order_line.update({'sequence': current_sequence,})
|
||||||
|
|
||||||
|
# order.partner_id.last_order_changed = datetime.now()
|
||||||
|
|
||||||
return order
|
return order
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
|
|
@ -520,6 +536,14 @@ class SaleOrder(models.Model):
|
||||||
vals['delivery_date'] = self.delivery_date
|
vals['delivery_date'] = self.delivery_date
|
||||||
|
|
||||||
res = super(SaleOrder, self).write(vals)
|
res = super(SaleOrder, self).write(vals)
|
||||||
|
|
||||||
|
# if self.partner_invoice_id.country_id != self.partner_shipping_id.country_id:
|
||||||
|
# message = _('Rechnungs- und Lieferland passen nicht zusammen: %s <-> %s!') % \
|
||||||
|
# (self.partner_invoice_id.country_id, self.partner_shipping_id.country_id)
|
||||||
|
#
|
||||||
|
# raise Warning(_(message))
|
||||||
|
#
|
||||||
|
|
||||||
if vals.get('assembly_state', False) == 'done':
|
if vals.get('assembly_state', False) == 'done':
|
||||||
self.message_post(body='Produktion fertig')
|
self.message_post(body='Produktion fertig')
|
||||||
|
|
||||||
|
|
@ -529,6 +553,8 @@ class SaleOrder(models.Model):
|
||||||
if vals.get('order_line',False):
|
if vals.get('order_line',False):
|
||||||
self._reset_sequence()
|
self._reset_sequence()
|
||||||
|
|
||||||
|
self.partner_id.last_order_changed = datetime.now()
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
|
|
@ -893,7 +919,7 @@ class SaleOrderLine(models.Model):
|
||||||
pricelist_id = self.order_id.partner_invoice_id.property_product_pricelist
|
pricelist_id = self.order_id.partner_invoice_id.property_product_pricelist
|
||||||
price, rule_id = pricelist_id.with_context(pricelist_context).get_product_price_rule(
|
price, rule_id = pricelist_id.with_context(pricelist_context).get_product_price_rule(
|
||||||
self.product_id, self.product_uom_qty or 1.0, self.order_id.partner_invoice_id)
|
self.product_id, self.product_uom_qty or 1.0, self.order_id.partner_invoice_id)
|
||||||
new_list_price, currency_id = self.with_context(context_partner)._get_real_price_currency(self.product_id,
|
new_list_price, currency_id = self.with_context(context_partner).sudo()._get_real_price_currency(self.product_id,
|
||||||
rule_id,
|
rule_id,
|
||||||
self.product_uom_qty,
|
self.product_uom_qty,
|
||||||
self.product_uom,
|
self.product_uom,
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,15 @@ from odoo import fields, models, api
|
||||||
class ResPartner(models.Model):
|
class ResPartner(models.Model):
|
||||||
_inherit = "res.partner"
|
_inherit = "res.partner"
|
||||||
|
|
||||||
|
# last_order = fields.Char(string="Letzter Auftrag", readonly=True, copy=False)
|
||||||
|
# last_order_date = fields.Date(string="Letztes Auftragsdatum", store=True, copy=False)
|
||||||
|
|
||||||
last_order = fields.Char(string="Letzter Auftrag", readonly=True, compute="get_last_order", store=True, copy=False)
|
last_order = fields.Char(string="Letzter Auftrag", readonly=True, compute="get_last_order", store=True, copy=False)
|
||||||
last_order_date = fields.Date(string="Letztes Auftragsdatum", readonly=True, compute="get_last_order", store=True, copy=False)
|
last_order_date = fields.Date(string="Letztes Auftragsdatum", readonly=True, compute="get_last_order", store=True, copy=False)
|
||||||
|
last_order_changed = fields.Date(string="Letzte Auftragsänderung", readonly=True, copy=False)
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
|
@api.depends('last_order_changed')
|
||||||
def get_last_order(self):
|
def get_last_order(self):
|
||||||
for partner in self:
|
for partner in self:
|
||||||
order_ids = self.env['sale.order'].search([('partner_id', '=', partner.id),
|
order_ids = self.env['sale.order'].search([('partner_id', '=', partner.id),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue