use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderLineController method supplierPartnerDomain.
/**
* Called on supplier partner select. Set the domain for the field supplierPartner
*
* @param request
* @param response
*/
public void supplierPartnerDomain(ActionRequest request, ActionResponse response) {
PurchaseOrderLine purchaseOrderLine = request.getContext().asType(PurchaseOrderLine.class);
PurchaseOrder purchaseOrder = request.getContext().getParent().asType(PurchaseOrder.class);
if (purchaseOrder.getId() != null) {
purchaseOrder = purchaseOrderLine.getPurchaseOrder();
}
Company company = purchaseOrder.getCompany();
String domain = "";
if (Beans.get(AppPurchaseService.class).getAppPurchase().getManageSupplierCatalog() && purchaseOrderLine.getProduct() != null && !purchaseOrderLine.getProduct().getSupplierCatalogList().isEmpty()) {
domain += "self.id != " + company.getPartner().getId() + " AND self.id IN " + purchaseOrderLine.getProduct().getSupplierCatalogList().stream().map(s -> s.getSupplierPartner().getId()).collect(Collectors.toList()).toString().replace('[', '(').replace(']', ')');
String blockedPartnerQuery = Beans.get(BlockingService.class).listOfBlockedPartner(company, BlockingRepository.PURCHASE_BLOCKING);
if (!Strings.isNullOrEmpty(blockedPartnerQuery)) {
domain += String.format(" AND self.id NOT in (%s)", blockedPartnerQuery);
}
} else {
domain += "self.id = 0";
}
domain += " AND " + company.getId() + " in (SELECT id FROM self.companySet)";
response.setAttr("supplierPartner", "domain", domain);
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderLineController method getPurchaseOrder.
public PurchaseOrder getPurchaseOrder(Context context) {
Context parentContext = context.getParent();
PurchaseOrder purchaseOrder = null;
if (parentContext != null && parentContext.getContextClass() == PurchaseOrder.class) {
purchaseOrder = parentContext.asType(PurchaseOrder.class);
if (!parentContext.getContextClass().toString().equals(PurchaseOrder.class.toString())) {
PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
purchaseOrder = purchaseOrderLine.getPurchaseOrder();
}
} else {
PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
purchaseOrder = purchaseOrderLine.getPurchaseOrder();
}
return purchaseOrder;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderLineController method getTaxEquiv.
public void getTaxEquiv(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
PurchaseOrder purchaseOrder = getPurchaseOrder(context);
response.setValue("taxEquiv", null);
if (purchaseOrder == null || purchaseOrderLine == null || purchaseOrder.getSupplierPartner() == null || purchaseOrderLine.getTaxLine() == null)
return;
response.setValue("taxEquiv", Beans.get(FiscalPositionService.class).getTaxEquiv(purchaseOrder.getSupplierPartner().getFiscalPosition(), purchaseOrderLine.getTaxLine().getTax()));
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderLineTaxService method createsPurchaseOrderLineTax.
/**
* Créer les lignes de TVA de la commande. La création des lignes de TVA se basent sur les lignes
* de commande.
*
* @param purchaseOrder La commande.
* @param purchaseOrderLineList Les lignes de commandes.
* @return La liste des lignes de TVA de la commande.
*/
public List<PurchaseOrderLineTax> createsPurchaseOrderLineTax(PurchaseOrder purchaseOrder, List<PurchaseOrderLine> purchaseOrderLineList) {
List<PurchaseOrderLineTax> purchaseOrderLineTaxList = new ArrayList<PurchaseOrderLineTax>();
Map<TaxLine, PurchaseOrderLineTax> map = new HashMap<TaxLine, PurchaseOrderLineTax>();
if (purchaseOrderLineList != null && !purchaseOrderLineList.isEmpty()) {
LOG.debug("Création des lignes de tva pour les lignes de commande.");
for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
TaxLine taxLine = purchaseOrderLine.getTaxLine();
TaxEquiv taxEquiv = purchaseOrderLine.getTaxEquiv();
TaxLine taxLineRC = (taxEquiv != null && taxEquiv.getReverseCharge() && taxEquiv.getReverseChargeTax() != null) ? taxEquiv.getReverseChargeTax().getActiveTaxLine() : null;
if (taxLine != null) {
LOG.debug("TVA {}", taxLine);
if (map.containsKey(taxLine)) {
PurchaseOrderLineTax purchaseOrderLineVat = map.get(taxLine);
purchaseOrderLineVat.setExTaxBase(purchaseOrderLineVat.getExTaxBase().add(purchaseOrderLine.getExTaxTotal()));
purchaseOrderLineVat.setReverseCharged(false);
} else {
PurchaseOrderLineTax purchaseOrderLineTax = new PurchaseOrderLineTax();
purchaseOrderLineTax.setPurchaseOrder(purchaseOrder);
purchaseOrderLineTax.setExTaxBase(purchaseOrderLine.getExTaxTotal());
purchaseOrderLineTax.setReverseCharged(false);
purchaseOrderLineTax.setTaxLine(taxLine);
map.put(taxLine, purchaseOrderLineTax);
}
}
if (taxLineRC != null) {
LOG.debug("TVA {}", taxLineRC);
if (map.containsKey(taxLineRC)) {
PurchaseOrderLineTax purchaseOrderLineRC = map.get(taxEquiv.getReverseChargeTax().getActiveTaxLine());
purchaseOrderLineRC.setExTaxBase(purchaseOrderLineRC.getExTaxBase().add(purchaseOrderLine.getExTaxTotal()));
purchaseOrderLineRC.setReverseCharged(true);
} else {
PurchaseOrderLineTax purchaseOrderLineTaxRC = new PurchaseOrderLineTax();
purchaseOrderLineTaxRC.setPurchaseOrder(purchaseOrder);
purchaseOrderLineTaxRC.setExTaxBase(purchaseOrderLine.getExTaxTotal());
purchaseOrderLineTaxRC.setReverseCharged(true);
purchaseOrderLineTaxRC.setTaxLine(taxLineRC);
map.put(taxLineRC, purchaseOrderLineTaxRC);
}
}
}
}
for (PurchaseOrderLineTax purchaseOrderLineTax : map.values()) {
// Dans la devise de la commande
BigDecimal exTaxBase = (purchaseOrderLineTax.getReverseCharged()) ? purchaseOrderLineTax.getExTaxBase().negate() : purchaseOrderLineTax.getExTaxBase();
BigDecimal taxTotal = BigDecimal.ZERO;
if (purchaseOrderLineTax.getTaxLine() != null)
taxTotal = purchaseOrderToolService.computeAmount(exTaxBase, purchaseOrderLineTax.getTaxLine().getValue());
purchaseOrderLineTax.setTaxTotal(taxTotal);
purchaseOrderLineTax.setInTaxTotal(purchaseOrderLineTax.getExTaxBase().add(taxTotal));
purchaseOrderLineTaxList.add(purchaseOrderLineTax);
LOG.debug("Ligne de TVA : Total TVA => {}, Total HT => {}", new Object[] { purchaseOrderLineTax.getTaxTotal(), purchaseOrderLineTax.getInTaxTotal() });
}
return purchaseOrderLineTaxList;
}
use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.
the class PurchaseOrderServiceImpl method _computePurchaseOrderLines.
@Override
public PurchaseOrder _computePurchaseOrderLines(PurchaseOrder purchaseOrder) throws AxelorException {
if (purchaseOrder.getPurchaseOrderLineList() != null) {
PurchaseOrderLineService purchaseOrderLineService = Beans.get(PurchaseOrderLineService.class);
for (PurchaseOrderLine purchaseOrderLine : purchaseOrder.getPurchaseOrderLineList()) {
purchaseOrderLine.setExTaxTotal(purchaseOrderLineService.computePurchaseOrderLine(purchaseOrderLine));
purchaseOrderLine.setCompanyExTaxTotal(purchaseOrderLineService.getCompanyExTaxTotal(purchaseOrderLine.getExTaxTotal(), purchaseOrder));
}
}
return purchaseOrder;
}
Aggregations