Use context to check model and field access
issue4081 review8481002
This commit is contained in:
+12
-22
@@ -17,10 +17,10 @@ def process_purchase(func):
|
||||
def wrapper(cls, invoices):
|
||||
pool = Pool()
|
||||
Purchase = pool.get('purchase.purchase')
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
with Transaction().set_context(_check_access=False):
|
||||
purchases = [p for i in cls.browse(invoices) for p in i.purchases]
|
||||
func(cls, invoices)
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
with Transaction().set_context(_check_access=False):
|
||||
Purchase.process(purchases)
|
||||
return wrapper
|
||||
|
||||
@@ -43,26 +43,17 @@ class Invoice:
|
||||
'an invoice generated by a purchase.'),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def get_purchase_exception_state(cls, invoices, name):
|
||||
Purchase = Pool().get('purchase.purchase')
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
purchases = Purchase.search([
|
||||
('invoices', 'in', [i.id for i in invoices]),
|
||||
])
|
||||
def get_purchase_exception_state(self, name):
|
||||
purchases = self.purchases
|
||||
|
||||
recreated = tuple(i for p in purchases for i in p.invoices_recreated)
|
||||
ignored = tuple(i for p in purchases for i in p.invoices_ignored)
|
||||
|
||||
res = {}
|
||||
for invoice in invoices:
|
||||
if invoice in recreated:
|
||||
res[invoice.id] = 'recreated'
|
||||
elif invoice in ignored:
|
||||
res[invoice.id] = 'ignored'
|
||||
else:
|
||||
res[invoice.id] = ''
|
||||
return res
|
||||
if self in recreated:
|
||||
return 'recreated'
|
||||
elif self in ignored:
|
||||
return 'ignored'
|
||||
return ''
|
||||
|
||||
def get_purchases(self, name):
|
||||
pool = Pool()
|
||||
@@ -96,10 +87,9 @@ class Invoice:
|
||||
@Workflow.transition('draft')
|
||||
def draft(cls, invoices):
|
||||
Purchase = Pool().get('purchase.purchase')
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
purchases = Purchase.search([
|
||||
('invoices', 'in', [i.id for i in invoices]),
|
||||
])
|
||||
purchases = Purchase.search([
|
||||
('invoices', 'in', [i.id for i in invoices]),
|
||||
])
|
||||
if purchases and any(i.state == 'cancel' for i in invoices):
|
||||
cls.raise_user_error('reset_invoice_purchase')
|
||||
|
||||
|
||||
+19
-25
@@ -708,17 +708,16 @@ class Purchase(Workflow, ModelSQL, ModelView):
|
||||
else:
|
||||
journal = None
|
||||
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
return Invoice(
|
||||
company=self.company,
|
||||
type=invoice_type,
|
||||
journal=journal,
|
||||
party=self.party,
|
||||
invoice_address=self.invoice_address,
|
||||
currency=self.currency,
|
||||
account=self.party.account_payable,
|
||||
payment_term=self.payment_term,
|
||||
)
|
||||
return Invoice(
|
||||
company=self.company,
|
||||
type=invoice_type,
|
||||
journal=journal,
|
||||
party=self.party,
|
||||
invoice_address=self.invoice_address,
|
||||
currency=self.currency,
|
||||
account=self.party.account_payable,
|
||||
payment_term=self.payment_term,
|
||||
)
|
||||
|
||||
def create_invoice(self, invoice_type):
|
||||
'''
|
||||
@@ -742,8 +741,7 @@ class Purchase(Workflow, ModelSQL, ModelView):
|
||||
invoice.lines = list(chain.from_iterable(invoice_lines.itervalues()))
|
||||
invoice.save()
|
||||
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
Invoice.update_taxes([invoice])
|
||||
Invoice.update_taxes([invoice])
|
||||
return invoice
|
||||
|
||||
def create_move(self, move_type):
|
||||
@@ -761,12 +759,11 @@ class Purchase(Workflow, ModelSQL, ModelView):
|
||||
|
||||
def _get_return_shipment(self):
|
||||
ShipmentInReturn = Pool().get('stock.shipment.in.return')
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
return ShipmentInReturn(
|
||||
company=self.company,
|
||||
from_location=self.warehouse.storage_location,
|
||||
to_location=self.party.supplier_location,
|
||||
)
|
||||
return ShipmentInReturn(
|
||||
company=self.company,
|
||||
from_location=self.warehouse.storage_location,
|
||||
to_location=self.party.supplier_location,
|
||||
)
|
||||
|
||||
def create_return_shipment(self, return_moves):
|
||||
'''
|
||||
@@ -776,8 +773,7 @@ class Purchase(Workflow, ModelSQL, ModelView):
|
||||
return_shipment = self._get_return_shipment()
|
||||
return_shipment.moves = return_moves
|
||||
return_shipment.save()
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
ShipmentInReturn.wait([return_shipment])
|
||||
ShipmentInReturn.wait([return_shipment])
|
||||
return return_shipment
|
||||
|
||||
def is_done(self):
|
||||
@@ -1228,8 +1224,7 @@ class PurchaseLine(ModelSQL, ModelView):
|
||||
Property = pool.get('ir.property')
|
||||
InvoiceLine = pool.get('account.invoice.line')
|
||||
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
invoice_line = InvoiceLine()
|
||||
invoice_line = InvoiceLine()
|
||||
invoice_line.type = self.type
|
||||
invoice_line.description = self.description
|
||||
invoice_line.note = self.note
|
||||
@@ -1338,8 +1333,7 @@ class PurchaseLine(ModelSQL, ModelView):
|
||||
'purchase': self.purchase.rec_name,
|
||||
'line': self.rec_name,
|
||||
})
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
move = Move()
|
||||
move = Move()
|
||||
move.quantity = quantity
|
||||
move.uom = self.unit
|
||||
move.product = self.product
|
||||
|
||||
@@ -65,7 +65,7 @@ class ShipmentIn:
|
||||
if purchase_line.purchase not in purchases:
|
||||
purchases.append(purchase_line.purchase)
|
||||
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
with Transaction().set_context(_check_access=False):
|
||||
purchases = Purchase.browse([p.id for p in purchases])
|
||||
Purchase.process(purchases)
|
||||
|
||||
@@ -118,7 +118,7 @@ class ShipmentInReturn:
|
||||
for purchase_line in purchase_lines:
|
||||
purchases.add(purchase_line.purchase)
|
||||
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
with Transaction().set_context(_check_access=False):
|
||||
purchases = Purchase.browse([p.id for p in purchases])
|
||||
Purchase.process(purchases)
|
||||
|
||||
@@ -278,9 +278,8 @@ class Move:
|
||||
])
|
||||
if purchase_lines:
|
||||
purchase_ids = list(set(l.purchase.id for l in purchase_lines))
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
purchases = Purchase.browse(purchase_ids)
|
||||
Purchase.process(purchases)
|
||||
purchases = Purchase.browse(purchase_ids)
|
||||
Purchase.process(purchases)
|
||||
|
||||
@classmethod
|
||||
def delete(cls, moves):
|
||||
@@ -299,7 +298,7 @@ class Move:
|
||||
for purchase_line in purchase_lines:
|
||||
purchases.add(purchase_line.purchase)
|
||||
if purchases:
|
||||
with Transaction().set_user(0, set_context=True):
|
||||
with Transaction().set_context(_check_access=False):
|
||||
purchases = Purchase.browse([p.id for p in purchases])
|
||||
Purchase.process(purchases)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user